<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{-
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

\section[CoreRules]{Rewrite rules}
-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-8"></span><span>
</span><span id="line-9"></span><span class="hs-comment">-- | Functions for collecting together and applying rewrite rules to a module.</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- The 'CoreRule' datatype itself is declared elsewhere.</span><span>
</span><span id="line-11"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Core.Rules</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-12"></span><span>        </span><span class="annot"><span class="hs-comment">-- ** Constructing</span></span><span>
</span><span id="line-13"></span><span>        </span><span class="annot"><a href="GHC.Core.Rules.html#emptyRuleBase"><span class="hs-identifier">emptyRuleBase</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#mkRuleBase"><span class="hs-identifier">mkRuleBase</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#extendRuleBaseList"><span class="hs-identifier">extendRuleBaseList</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-14"></span><span>        </span><span class="annot"><a href="GHC.Core.Rules.html#unionRuleBase"><span class="hs-identifier">unionRuleBase</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#pprRuleBase"><span class="hs-identifier">pprRuleBase</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-15"></span><span>
</span><span id="line-16"></span><span>        </span><span class="annot"><span class="hs-comment">-- ** Checking rule applications</span></span><span>
</span><span id="line-17"></span><span>        </span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheckProgram"><span class="hs-identifier">ruleCheckProgram</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span>        </span><span class="annot"><span class="hs-comment">-- ** Manipulating 'RuleInfo' rules</span></span><span>
</span><span id="line-20"></span><span>        </span><span class="annot"><a href="GHC.Core.Rules.html#extendRuleInfo"><span class="hs-identifier">extendRuleInfo</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#addRuleInfo"><span class="hs-identifier">addRuleInfo</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>        </span><span class="annot"><a href="GHC.Core.Rules.html#addIdSpecialisations"><span class="hs-identifier">addIdSpecialisations</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>
</span><span id="line-23"></span><span>        </span><span class="annot"><span class="hs-comment">-- * Misc. CoreRule helpers</span></span><span>
</span><span id="line-24"></span><span>        </span><span class="annot"><a href="GHC.Core.Rules.html#rulesOfBinds"><span class="hs-identifier">rulesOfBinds</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#getRules"><span class="hs-identifier">getRules</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#pprRulesForUser"><span class="hs-identifier">pprRulesForUser</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span>        </span><span class="annot"><a href="GHC.Core.Rules.html#lookupRule"><span class="hs-identifier">lookupRule</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#mkRule"><span class="hs-identifier">mkRule</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#roughTopNames"><span class="hs-identifier">roughTopNames</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#initRuleOpts"><span class="hs-identifier">initRuleOpts</span></a></span><span>
</span><span id="line-27"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-32"></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.html"><span class="hs-identifier">GHC.Core</span></a></span><span>         </span><span class="hs-comment">-- All of it</span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Unit.Module.html"><span class="hs-identifier">GHC.Unit.Module</span></a></span><span>   </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier">Module</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Unit.Module.Env.html"><span class="hs-identifier">GHC.Unit.Module.Env</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Subst.html"><span class="hs-identifier">GHC.Core.Subst</span></a></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.SimpleOpt.html"><span class="hs-identifier">GHC.Core.SimpleOpt</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.SimpleOpt.html#exprIsLambda_maybe"><span class="hs-identifier">exprIsLambda_maybe</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html"><span class="hs-identifier">GHC.Core.FVs</span></a></span><span>       </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#exprFreeVars"><span class="hs-identifier">exprFreeVars</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#exprsFreeVars"><span class="hs-identifier">exprsFreeVars</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#bindFreeVars"><span class="hs-identifier">bindFreeVars</span></a></span><span>
</span><span id="line-39"></span><span>                          </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#rulesFreeVarsDSet"><span class="hs-identifier">rulesFreeVarsDSet</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#exprsOrphNames"><span class="hs-identifier">exprsOrphNames</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#exprFreeVarsList"><span class="hs-identifier">exprFreeVarsList</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html"><span class="hs-identifier">GHC.Core.Utils</span></a></span><span>     </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#exprType"><span class="hs-identifier">exprType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#eqExpr"><span class="hs-identifier">eqExpr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#mkTick"><span class="hs-identifier">mkTick</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#mkTicks"><span class="hs-identifier">mkTicks</span></a></span><span>
</span><span id="line-41"></span><span>                          </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#stripTicksTopT"><span class="hs-identifier">stripTicksTopT</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#stripTicksTopE"><span class="hs-identifier">stripTicksTopE</span></a></span><span>
</span><span id="line-42"></span><span>                          </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#isJoinBind"><span class="hs-identifier">isJoinBind</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Ppr.html"><span class="hs-identifier">GHC.Core.Ppr</span></a></span><span>       </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Ppr.html#pprRules"><span class="hs-identifier">pprRules</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Type</span></span><span>
</span><span id="line-45"></span><span>   </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier">Type</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#TCvSubst"><span class="hs-identifier">TCvSubst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#extendTvSubst"><span class="hs-identifier">extendTvSubst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#extendCvSubst"><span class="hs-identifier">extendCvSubst</span></a></span><span>
</span><span id="line-46"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#mkEmptyTCvSubst"><span class="hs-identifier">mkEmptyTCvSubst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#substTy"><span class="hs-identifier">substTy</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html"><span class="hs-identifier">GHC.Tc.Utils.TcType</span></a></span><span>  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Type.html#tcSplitTyConApp_maybe"><span class="hs-identifier">tcSplitTyConApp_maybe</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Builtin.Types.html"><span class="hs-identifier">GHC.Builtin.Types</span></a></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Builtin.Types.html#anyTypeOfKind"><span class="hs-identifier">anyTypeOfKind</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.html"><span class="hs-identifier">GHC.Core.Coercion</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Coercion</span></span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Tidy.html"><span class="hs-identifier">GHC.Core.Tidy</span></a></span><span>     </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Tidy.html#tidyRules"><span class="hs-identifier">tidyRules</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.html"><span class="hs-identifier">GHC.Types.Id</span></a></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html"><span class="hs-identifier">GHC.Types.Id.Info</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier">RuleInfo</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier">RuleInfo</span></a></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.html"><span class="hs-identifier">GHC.Types.Var</span></a></span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html"><span class="hs-identifier">GHC.Types.Var.Env</span></a></span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.html"><span class="hs-identifier">GHC.Types.Name</span></a></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier">Name</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Name.html#NamedThing"><span class="hs-identifier">NamedThing</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Name.html#nameIsLocalOrFrom"><span class="hs-identifier">nameIsLocalOrFrom</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.Set.html"><span class="hs-identifier">GHC.Types.Name.Set</span></a></span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.Env.html"><span class="hs-identifier">GHC.Types.Name.Env</span></a></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Unique.FM.html"><span class="hs-identifier">GHC.Types.Unique.FM</span></a></span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html"><span class="hs-identifier">GHC.Core.Unify</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Unify</span></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html#ruleMatchTyKiX"><span class="hs-identifier">ruleMatchTyKiX</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html"><span class="hs-identifier">GHC.Types.Basic</span></a></span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>      </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier">DynFlags</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier">gopt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#targetPlatform"><span class="hs-identifier">targetPlatform</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Flags.html"><span class="hs-identifier">GHC.Driver.Flags</span></a></span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.FastString.html"><span class="hs-identifier">GHC.Data.FastString</span></a></span><span>
</span><span id="line-66"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html"><span class="hs-identifier">GHC.Data.Maybe</span></a></span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html"><span class="hs-identifier">GHC.Data.Bag</span></a></span><span>
</span><span id="line-68"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Utils</span></span><span>
</span><span id="line-69"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span>
</span><span id="line-70"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Ord.html#"><span class="hs-identifier">Data.Ord</span></a></span><span>
</span><span id="line-71"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#guard"><span class="hs-identifier">guard</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span class="hs-comment">{-
Note [Overall plumbing for rules]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* After the desugarer:
   - The ModGuts initially contains mg_rules :: [CoreRule] of
     locally-declared rules for imported Ids.
   - Locally-declared rules for locally-declared Ids are attached to
     the IdInfo for that Id.  See Note [Attach rules to local ids] in
     GHC.HsToCore.Binds

* GHC.Iface.Tidy strips off all the rules from local Ids and adds them to
  mg_rules, so that the ModGuts has *all* the locally-declared rules.

* The HomePackageTable contains a ModDetails for each home package
  module.  Each contains md_rules :: [CoreRule] of rules declared in
  that module.  The HomePackageTable grows as ghc --make does its
  up-sweep.  In batch mode (ghc -c), the HPT is empty; all imported modules
  are treated by the &quot;external&quot; route, discussed next, regardless of
  which package they come from.

* The ExternalPackageState has a single eps_rule_base :: RuleBase for
  Ids in other packages.  This RuleBase simply grow monotonically, as
  ghc --make compiles one module after another.

  During simplification, interface files may get demand-loaded,
  as the simplifier explores the unfoldings for Ids it has in
  its hand.  (Via an unsafePerformIO; the EPS is really a cache.)
  That in turn may make the EPS rule-base grow.  In contrast, the
  HPT never grows in this way.

* The result of all this is that during Core-to-Core optimisation
  there are four sources of rules:

    (a) Rules in the IdInfo of the Id they are a rule for.  These are
        easy: fast to look up, and if you apply a substitution then
        it'll be applied to the IdInfo as a matter of course.

    (b) Rules declared in this module for imported Ids, kept in the
        ModGuts. If you do a substitution, you'd better apply the
        substitution to these.  There are seldom many of these.

    (c) Rules declared in the HomePackageTable.  These never change.

    (d) Rules in the ExternalPackageTable. These can grow in response
        to lazy demand-loading of interfaces.

* At the moment (c) is carried in a reader-monad way by the GHC.Core.Opt.Monad.
  The HomePackageTable doesn't have a single RuleBase because technically
  we should only be able to &quot;see&quot; rules &quot;below&quot; this module; so we
  generate a RuleBase for (c) by combing rules from all the modules
  &quot;below&quot; us.  That's why we can't just select the home-package RuleBase
  from HscEnv.

  [NB: we are inconsistent here.  We should do the same for external
  packages, but we don't.  Same for type-class instances.]

* So in the outer simplifier loop, we combine (b-d) into a single
  RuleBase, reading
     (b) from the ModGuts,
     (c) from the GHC.Core.Opt.Monad, and
     (d) from its mutable variable
  [Of course this means that we won't see new EPS rules that come in
  during a single simplifier iteration, but that probably does not
  matter.]


************************************************************************
*                                                                      *
\subsection[specialisation-IdInfo]{Specialisation info about an @Id@}
*                                                                      *
************************************************************************

A @CoreRule@ holds details of one rule for an @Id@, which
includes its specialisations.

For example, if a rule for @f@ contains the mapping:
\begin{verbatim}
        forall a b d. [Type (List a), Type b, Var d]  ===&gt;  f' a b
\end{verbatim}
then when we find an application of f to matching types, we simply replace
it by the matching RHS:
\begin{verbatim}
        f (List Int) Bool dict ===&gt;  f' Int Bool
\end{verbatim}
All the stuff about how many dictionaries to discard, and what types
to apply the specialised function to, are handled by the fact that the
Rule contains a template for the result of the specialisation.

There is one more exciting case, which is dealt with in exactly the same
way.  If the specialised value is unboxed then it is lifted at its
definition site and unlifted at its uses.  For example:

        pi :: forall a. Num a =&gt; a

might have a specialisation

        [Int#] ===&gt;  (case pi' of Lift pi# -&gt; pi#)

where pi' :: Lift Int# is the specialised version of pi.
-}</span><span>
</span><span id="line-173"></span><span>
</span><span id="line-174"></span><span class="annot"><a href="GHC.Core.Rules.html#mkRule"><span class="hs-identifier hs-type">mkRule</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#RuleName"><span class="hs-identifier hs-type">RuleName</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Activation"><span class="hs-identifier hs-type">Activation</span></a></span><span>
</span><span id="line-175"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreBndr"><span class="hs-identifier hs-type">CoreBndr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span>
</span><span id="line-176"></span><span class="hs-comment">-- ^ Used to make 'CoreRule' for an 'Id' defined in the module being</span><span>
</span><span id="line-177"></span><span class="hs-comment">-- compiled. See also 'GHC.Core.CoreRule'</span><span>
</span><span id="line-178"></span><span id="mkRule"><span class="annot"><span class="annottext">mkRule :: Module
-&gt; Bool
-&gt; Bool
-&gt; RuleName
-&gt; Activation
-&gt; Name
-&gt; [Var]
-&gt; [CoreExpr]
-&gt; CoreExpr
-&gt; CoreRule
</span><a href="GHC.Core.Rules.html#mkRule"><span class="hs-identifier hs-var hs-var">mkRule</span></a></span></span><span> </span><span id="local-6989586621680964574"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680964574"><span class="hs-identifier hs-var">this_mod</span></a></span></span><span> </span><span id="local-6989586621680964573"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680964573"><span class="hs-identifier hs-var">is_auto</span></a></span></span><span> </span><span id="local-6989586621680964572"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680964572"><span class="hs-identifier hs-var">is_local</span></a></span></span><span> </span><span id="local-6989586621680964571"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680964571"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span id="local-6989586621680964570"><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680964570"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span id="local-6989586621680964569"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680964569"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span id="local-6989586621680964568"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964568"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span> </span><span id="local-6989586621680964567"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964567"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680964566"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964566"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-179"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Rule :: RuleName
-&gt; Activation
-&gt; Name
-&gt; [Maybe Name]
-&gt; [Var]
-&gt; [CoreExpr]
-&gt; CoreExpr
-&gt; Bool
-&gt; Module
-&gt; IsOrphan
-&gt; Bool
-&gt; CoreRule
</span><a href="GHC.Core.html#Rule"><span class="hs-identifier hs-type">Rule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_name :: RuleName
</span><a href="GHC.Core.html#ru_name"><span class="hs-identifier hs-var">ru_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680964571"><span class="hs-identifier hs-var">name</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_fn :: Name
</span><a href="GHC.Core.html#ru_fn"><span class="hs-identifier hs-var">ru_fn</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680964569"><span class="hs-identifier hs-var">fn</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_act :: Activation
</span><a href="GHC.Core.html#ru_act"><span class="hs-identifier hs-var">ru_act</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680964570"><span class="hs-identifier hs-var">act</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-180"></span><span>           </span><span class="annot"><span class="annottext">ru_bndrs :: [Var]
</span><a href="GHC.Core.html#ru_bndrs"><span class="hs-identifier hs-var">ru_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964568"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_args :: [CoreExpr]
</span><a href="GHC.Core.html#ru_args"><span class="hs-identifier hs-var">ru_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964567"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-181"></span><span>           </span><span class="annot"><span class="annottext">ru_rhs :: CoreExpr
</span><a href="GHC.Core.html#ru_rhs"><span class="hs-identifier hs-var">ru_rhs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964566"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-182"></span><span>           </span><span class="annot"><span class="annottext">ru_rough :: [Maybe Name]
</span><a href="GHC.Core.html#ru_rough"><span class="hs-identifier hs-var">ru_rough</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreExpr] -&gt; [Maybe Name]
</span><a href="GHC.Core.Rules.html#roughTopNames"><span class="hs-identifier hs-var">roughTopNames</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964567"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-183"></span><span>           </span><span class="annot"><span class="annottext">ru_origin :: Module
</span><a href="GHC.Core.html#ru_origin"><span class="hs-identifier hs-var">ru_origin</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680964574"><span class="hs-identifier hs-var">this_mod</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-184"></span><span>           </span><span class="annot"><span class="annottext">ru_orphan :: IsOrphan
</span><a href="GHC.Core.html#ru_orphan"><span class="hs-identifier hs-var">ru_orphan</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IsOrphan
</span><a href="#local-6989586621680964555"><span class="hs-identifier hs-var">orph</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-185"></span><span>           </span><span class="annot"><span class="annottext">ru_auto :: Bool
</span><a href="GHC.Core.html#ru_auto"><span class="hs-identifier hs-var">ru_auto</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680964573"><span class="hs-identifier hs-var">is_auto</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_local :: Bool
</span><a href="GHC.Core.html#ru_local"><span class="hs-identifier hs-var">ru_local</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680964572"><span class="hs-identifier hs-var">is_local</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-186"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-187"></span><span>        </span><span class="hs-comment">-- Compute orphanhood.  See Note [Orphans] in GHC.Core.InstEnv</span><span>
</span><span id="line-188"></span><span>        </span><span class="hs-comment">-- A rule is an orphan only if none of the variables</span><span>
</span><span id="line-189"></span><span>        </span><span class="hs-comment">-- mentioned on its left-hand side are locally defined</span><span>
</span><span id="line-190"></span><span>    </span><span id="local-6989586621680964552"><span class="annot"><span class="annottext">lhs_names :: NameSet
</span><a href="#local-6989586621680964552"><span class="hs-identifier hs-var hs-var">lhs_names</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NameSet -&gt; Name -&gt; NameSet
</span><a href="GHC.Types.Name.Set.html#extendNameSet"><span class="hs-identifier hs-var">extendNameSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreExpr] -&gt; NameSet
</span><a href="GHC.Core.FVs.html#exprsOrphNames"><span class="hs-identifier hs-var">exprsOrphNames</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964567"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680964569"><span class="hs-identifier hs-var">fn</span></a></span><span>
</span><span id="line-191"></span><span>
</span><span id="line-192"></span><span>        </span><span class="hs-comment">-- Since rules get eventually attached to one of the free names</span><span>
</span><span id="line-193"></span><span>        </span><span class="hs-comment">-- from the definition when compiling the ABI hash, we should make</span><span>
</span><span id="line-194"></span><span>        </span><span class="hs-comment">-- it deterministic. This chooses the one with minimal OccName</span><span>
</span><span id="line-195"></span><span>        </span><span class="hs-comment">-- as opposed to uniq value.</span><span>
</span><span id="line-196"></span><span>    </span><span id="local-6989586621680964550"><span class="annot"><span class="annottext">local_lhs_names :: NameSet
</span><a href="#local-6989586621680964550"><span class="hs-identifier hs-var hs-var">local_lhs_names</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Name -&gt; Bool) -&gt; NameSet -&gt; NameSet
</span><a href="GHC.Types.Name.Set.html#filterNameSet"><span class="hs-identifier hs-var">filterNameSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Module -&gt; Name -&gt; Bool
</span><a href="GHC.Types.Name.html#nameIsLocalOrFrom"><span class="hs-identifier hs-var">nameIsLocalOrFrom</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680964574"><span class="hs-identifier hs-var">this_mod</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">NameSet
</span><a href="#local-6989586621680964552"><span class="hs-identifier hs-var">lhs_names</span></a></span><span>
</span><span id="line-197"></span><span>    </span><span id="local-6989586621680964555"><span class="annot"><span class="annottext">orph :: IsOrphan
</span><a href="#local-6989586621680964555"><span class="hs-identifier hs-var hs-var">orph</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NameSet -&gt; IsOrphan
</span><a href="GHC.Core.html#chooseOrphanAnchor"><span class="hs-identifier hs-var">chooseOrphanAnchor</span></a></span><span> </span><span class="annot"><span class="annottext">NameSet
</span><a href="#local-6989586621680964550"><span class="hs-identifier hs-var">local_lhs_names</span></a></span><span>
</span><span id="line-198"></span><span>
</span><span id="line-199"></span><span class="hs-comment">--------------</span><span>
</span><span id="line-200"></span><span class="annot"><a href="GHC.Core.Rules.html#roughTopNames"><span class="hs-identifier hs-type">roughTopNames</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-201"></span><span class="hs-comment">-- ^ Find the \&quot;top\&quot; free names of several expressions.</span><span>
</span><span id="line-202"></span><span class="hs-comment">-- Such names are either:</span><span>
</span><span id="line-203"></span><span class="hs-comment">--</span><span>
</span><span id="line-204"></span><span class="hs-comment">-- 1. The function finally being applied to in an application chain</span><span>
</span><span id="line-205"></span><span class="hs-comment">--    (if that name is a GlobalId: see &quot;GHC.Types.Var#globalvslocal&quot;), or</span><span>
</span><span id="line-206"></span><span class="hs-comment">--</span><span>
</span><span id="line-207"></span><span class="hs-comment">-- 2. The 'TyCon' if the expression is a 'Type'</span><span>
</span><span id="line-208"></span><span class="hs-comment">--</span><span>
</span><span id="line-209"></span><span class="hs-comment">-- This is used for the fast-match-check for rules;</span><span>
</span><span id="line-210"></span><span class="hs-comment">--      if the top names don't match, the rest can't</span><span>
</span><span id="line-211"></span><span id="roughTopNames"><span class="annot"><span class="annottext">roughTopNames :: [CoreExpr] -&gt; [Maybe Name]
</span><a href="GHC.Core.Rules.html#roughTopNames"><span class="hs-identifier hs-var hs-var">roughTopNames</span></a></span></span><span> </span><span id="local-6989586621680964547"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964547"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; Maybe Name) -&gt; [CoreExpr] -&gt; [Maybe Name]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Maybe Name
</span><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964547"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-212"></span><span>
</span><span id="line-213"></span><span class="annot"><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-type">roughTopName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span>
</span><span id="line-214"></span><span id="roughTopName"><span class="annot"><span class="annottext">roughTopName :: CoreExpr -&gt; Maybe Name
</span><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var hs-var">roughTopName</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span id="local-6989586621680964544"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964544"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; Type -&gt; Maybe (TyCon, [Type])
Type -&gt; Maybe (TyCon, [Type])
</span><a href="GHC.Core.Type.html#tcSplitTyConApp_maybe"><span class="hs-identifier hs-var">tcSplitTyConApp_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964544"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-215"></span><span>                               </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964543"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680964543"><span class="hs-identifier hs-var">tc</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Maybe Name
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Name
forall a. NamedThing a =&gt; a -&gt; Name
</span><a href="GHC.Types.Name.html#getName"><span class="hs-identifier hs-var">getName</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680964543"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-216"></span><span>                               </span><span class="annot"><span class="annottext">Maybe (TyCon, [Type])
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe Name
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-217"></span><span class="annot"><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Name
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-218"></span><span class="annot"><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680964539"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964539"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Maybe Name
</span><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964539"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-219"></span><span class="annot"><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680964537"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964537"><span class="hs-identifier hs-var">f</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isGlobalId"><span class="hs-identifier hs-var">isGlobalId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964537"><span class="hs-identifier hs-var">f</span></a></span><span>   </span><span class="hs-comment">-- Note [Care with roughTopName]</span><span>
</span><span id="line-220"></span><span>                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isDataConWorkId"><span class="hs-identifier hs-var">isDataConWorkId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964537"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Var -&gt; Arity
</span><a href="GHC.Types.Id.html#idArity"><span class="hs-identifier hs-var">idArity</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964537"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span>
</span><span id="line-221"></span><span>                       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Maybe Name
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Name
</span><a href="GHC.Types.Id.html#idName"><span class="hs-identifier hs-var">idName</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964537"><span class="hs-identifier hs-var">f</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-222"></span><span class="annot"><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680964529"><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680964529"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680964528"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964528"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680964529"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-223"></span><span>                        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Maybe Name
</span><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964528"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-224"></span><span class="annot"><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Name
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-225"></span><span>
</span><span id="line-226"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCantMatch"><span class="hs-identifier hs-type">ruleCantMatch</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-227"></span><span class="hs-comment">-- ^ @ruleCantMatch tpl actual@ returns True only if @actual@</span><span>
</span><span id="line-228"></span><span class="hs-comment">-- definitely can't match @tpl@ by instantiating @tpl@.</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- It's only a one-way match; unlike instance matching we</span><span>
</span><span id="line-230"></span><span class="hs-comment">-- don't consider unification.</span><span>
</span><span id="line-231"></span><span class="hs-comment">--</span><span>
</span><span id="line-232"></span><span class="hs-comment">-- Notice that [_$_]</span><span>
</span><span id="line-233"></span><span class="hs-comment">--      @ruleCantMatch [Nothing] [Just n2] = False@</span><span>
</span><span id="line-234"></span><span class="hs-comment">--      Reason: a template variable can be instantiated by a constant</span><span>
</span><span id="line-235"></span><span class="hs-comment">-- Also:</span><span>
</span><span id="line-236"></span><span class="hs-comment">--      @ruleCantMatch [Just n1] [Nothing] = False@</span><span>
</span><span id="line-237"></span><span class="hs-comment">--      Reason: a local variable @v@ in the actuals might [_$_]</span><span>
</span><span id="line-238"></span><span>
</span><span id="line-239"></span><span id="ruleCantMatch"><span class="annot"><span class="annottext">ruleCantMatch :: [Maybe Name] -&gt; [Maybe Name] -&gt; Bool
</span><a href="GHC.Core.Rules.html#ruleCantMatch"><span class="hs-identifier hs-var hs-var">ruleCantMatch</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964525"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680964525"><span class="hs-identifier hs-var">n1</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680964524"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964524"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964523"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680964523"><span class="hs-identifier hs-var">n2</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680964522"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964522"><span class="hs-keyword hs-var">as</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680964525"><span class="hs-identifier hs-var">n1</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; Name -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">/=</span></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680964523"><span class="hs-identifier hs-var">n2</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">[Maybe Name] -&gt; [Maybe Name] -&gt; Bool
</span><a href="GHC.Core.Rules.html#ruleCantMatch"><span class="hs-identifier hs-var">ruleCantMatch</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964524"><span class="hs-identifier hs-var">ts</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964522"><span class="hs-keyword hs-var">as</span></a></span><span>
</span><span id="line-240"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCantMatch"><span class="hs-identifier hs-var">ruleCantMatch</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Name
</span><span class="hs-identifier">_</span></span><span>       </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680964520"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964520"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Name
</span><span class="hs-identifier">_</span></span><span>       </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680964519"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964519"><span class="hs-keyword hs-var">as</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Maybe Name] -&gt; [Maybe Name] -&gt; Bool
</span><a href="GHC.Core.Rules.html#ruleCantMatch"><span class="hs-identifier hs-var">ruleCantMatch</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964520"><span class="hs-identifier hs-var">ts</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964519"><span class="hs-keyword hs-var">as</span></a></span><span>
</span><span id="line-241"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCantMatch"><span class="hs-identifier hs-var">ruleCantMatch</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><span class="hs-identifier">_</span></span><span>              </span><span class="annot"><span class="annottext">[Maybe Name]
</span><span class="hs-identifier">_</span></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-242"></span><span>
</span><span id="line-243"></span><span class="hs-comment">{-
Note [Care with roughTopName]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this
    module M where { x = a:b }
    module N where { ...f x...
                     RULE f (p:q) = ... }
You'd expect the rule to match, because the matcher can
look through the unfolding of 'x'.  So we must avoid roughTopName
returning 'M.x' for the call (f x), or else it'll say &quot;can't match&quot;
and we won't even try!!

However, suppose we have
         RULE g (M.h x) = ...
         foo = ...(g (M.k v))....
where k is a *function* exported by M.  We never really match
functions (lambdas) except by name, so in this case it seems like
a good idea to treat 'M.k' as a roughTopName of the call.
-}</span><span>
</span><span id="line-262"></span><span>
</span><span id="line-263"></span><span class="annot"><a href="GHC.Core.Rules.html#pprRulesForUser"><span class="hs-identifier hs-type">pprRulesForUser</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-264"></span><span class="hs-comment">-- (a) tidy the rules</span><span>
</span><span id="line-265"></span><span class="hs-comment">-- (b) sort them into order based on the rule name</span><span>
</span><span id="line-266"></span><span class="hs-comment">-- (c) suppress uniques (unless -dppr-debug is on)</span><span>
</span><span id="line-267"></span><span class="hs-comment">-- This combination makes the output stable so we can use in testing</span><span>
</span><span id="line-268"></span><span class="hs-comment">-- It's here rather than in GHC.Core.Ppr because it calls tidyRules</span><span>
</span><span id="line-269"></span><span id="pprRulesForUser"><span class="annot"><span class="annottext">pprRulesForUser :: [CoreRule] -&gt; SDoc
</span><a href="GHC.Core.Rules.html#pprRulesForUser"><span class="hs-identifier hs-var hs-var">pprRulesForUser</span></a></span></span><span> </span><span id="local-6989586621680964518"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964518"><span class="hs-identifier hs-var">rules</span></a></span></span><span>
</span><span id="line-270"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PprStyle -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#withPprStyle"><span class="hs-identifier hs-var">withPprStyle</span></a></span><span> </span><span class="annot"><span class="annottext">PprStyle
</span><a href="GHC.Utils.Outputable.html#defaultUserStyle"><span class="hs-identifier hs-var">defaultUserStyle</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; SDoc) -&gt; SDoc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-271"></span><span>    </span><span class="annot"><span class="annottext">[CoreRule] -&gt; SDoc
</span><a href="GHC.Core.Ppr.html#pprRules"><span class="hs-identifier hs-var">pprRules</span></a></span><span> </span><span class="annot"><span class="annottext">([CoreRule] -&gt; SDoc) -&gt; [CoreRule] -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-272"></span><span>    </span><span class="annot"><span class="annottext">(CoreRule -&gt; CoreRule -&gt; Ordering) -&gt; [CoreRule] -&gt; [CoreRule]
forall a. (a -&gt; a -&gt; Ordering) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/Data.OldList.html#sortBy"><span class="hs-identifier hs-var">sortBy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(CoreRule -&gt; RuleName) -&gt; CoreRule -&gt; CoreRule -&gt; Ordering
forall a b. Ord a =&gt; (b -&gt; a) -&gt; b -&gt; b -&gt; Ordering
</span><a href="../../base/src/Data.Ord.html#comparing"><span class="hs-identifier hs-var">comparing</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; RuleName
</span><a href="GHC.Core.html#ruleName"><span class="hs-identifier hs-var">ruleName</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([CoreRule] -&gt; [CoreRule]) -&gt; [CoreRule] -&gt; [CoreRule]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-273"></span><span>    </span><span class="annot"><span class="annottext">TidyEnv -&gt; [CoreRule] -&gt; [CoreRule]
</span><a href="GHC.Core.Tidy.html#tidyRules"><span class="hs-identifier hs-var">tidyRules</span></a></span><span> </span><span class="annot"><span class="annottext">TidyEnv
</span><a href="GHC.Types.Var.Env.html#emptyTidyEnv"><span class="hs-identifier hs-var">emptyTidyEnv</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964518"><span class="hs-identifier hs-var">rules</span></a></span><span>
</span><span id="line-274"></span><span>
</span><span id="line-275"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                RuleInfo: the rules in an IdInfo
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-282"></span><span>
</span><span id="line-283"></span><span class="annot"><a href="GHC.Core.Rules.html#extendRuleInfo"><span class="hs-identifier hs-type">extendRuleInfo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-type">RuleInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-type">RuleInfo</span></a></span><span>
</span><span id="line-284"></span><span id="extendRuleInfo"><span class="annot"><span class="annottext">extendRuleInfo :: RuleInfo -&gt; [CoreRule] -&gt; RuleInfo
</span><a href="GHC.Core.Rules.html#extendRuleInfo"><span class="hs-identifier hs-var hs-var">extendRuleInfo</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-type">RuleInfo</span></a></span><span> </span><span id="local-6989586621680964511"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964511"><span class="hs-identifier hs-var">rs1</span></a></span></span><span> </span><span id="local-6989586621680964510"><span class="annot"><span class="annottext">DVarSet
</span><a href="#local-6989586621680964510"><span class="hs-identifier hs-var">fvs1</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680964509"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964509"><span class="hs-identifier hs-var">rs2</span></a></span></span><span>
</span><span id="line-285"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; DVarSet -&gt; RuleInfo
</span><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-var">RuleInfo</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964509"><span class="hs-identifier hs-var">rs2</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; [CoreRule] -&gt; [CoreRule]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964511"><span class="hs-identifier hs-var">rs1</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreRule] -&gt; DVarSet
</span><a href="GHC.Core.FVs.html#rulesFreeVarsDSet"><span class="hs-identifier hs-var">rulesFreeVarsDSet</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964509"><span class="hs-identifier hs-var">rs2</span></a></span><span> </span><span class="annot"><span class="annottext">DVarSet -&gt; DVarSet -&gt; DVarSet
</span><a href="GHC.Types.Var.Set.html#unionDVarSet"><span class="hs-operator hs-var">`unionDVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">DVarSet
</span><a href="#local-6989586621680964510"><span class="hs-identifier hs-var">fvs1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-286"></span><span>
</span><span id="line-287"></span><span class="annot"><a href="GHC.Core.Rules.html#addRuleInfo"><span class="hs-identifier hs-type">addRuleInfo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-type">RuleInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-type">RuleInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-type">RuleInfo</span></a></span><span>
</span><span id="line-288"></span><span id="addRuleInfo"><span class="annot"><span class="annottext">addRuleInfo :: RuleInfo -&gt; RuleInfo -&gt; RuleInfo
</span><a href="GHC.Core.Rules.html#addRuleInfo"><span class="hs-identifier hs-var hs-var">addRuleInfo</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-type">RuleInfo</span></a></span><span> </span><span id="local-6989586621680964507"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964507"><span class="hs-identifier hs-var">rs1</span></a></span></span><span> </span><span id="local-6989586621680964506"><span class="annot"><span class="annottext">DVarSet
</span><a href="#local-6989586621680964506"><span class="hs-identifier hs-var">fvs1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-type">RuleInfo</span></a></span><span> </span><span id="local-6989586621680964505"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964505"><span class="hs-identifier hs-var">rs2</span></a></span></span><span> </span><span id="local-6989586621680964504"><span class="annot"><span class="annottext">DVarSet
</span><a href="#local-6989586621680964504"><span class="hs-identifier hs-var">fvs2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-289"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; DVarSet -&gt; RuleInfo
</span><a href="GHC.Types.Id.Info.html#RuleInfo"><span class="hs-identifier hs-var">RuleInfo</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964507"><span class="hs-identifier hs-var">rs1</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; [CoreRule] -&gt; [CoreRule]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964505"><span class="hs-identifier hs-var">rs2</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DVarSet
</span><a href="#local-6989586621680964506"><span class="hs-identifier hs-var">fvs1</span></a></span><span> </span><span class="annot"><span class="annottext">DVarSet -&gt; DVarSet -&gt; DVarSet
</span><a href="GHC.Types.Var.Set.html#unionDVarSet"><span class="hs-operator hs-var">`unionDVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">DVarSet
</span><a href="#local-6989586621680964504"><span class="hs-identifier hs-var">fvs2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-290"></span><span>
</span><span id="line-291"></span><span class="annot"><a href="GHC.Core.Rules.html#addIdSpecialisations"><span class="hs-identifier hs-type">addIdSpecialisations</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>
</span><span id="line-292"></span><span id="addIdSpecialisations"><span class="annot"><span class="annottext">addIdSpecialisations :: Var -&gt; [CoreRule] -&gt; Var
</span><a href="GHC.Core.Rules.html#addIdSpecialisations"><span class="hs-identifier hs-var hs-var">addIdSpecialisations</span></a></span></span><span> </span><span id="local-6989586621680964502"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964502"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680964501"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964501"><span class="hs-identifier hs-var">rules</span></a></span></span><span>
</span><span id="line-293"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964501"><span class="hs-identifier hs-var">rules</span></a></span><span>
</span><span id="line-294"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964502"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-295"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-296"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; RuleInfo -&gt; Var
</span><a href="GHC.Types.Id.html#setIdSpecialisation"><span class="hs-identifier hs-var">setIdSpecialisation</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964502"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">(RuleInfo -&gt; Var) -&gt; RuleInfo -&gt; Var
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-297"></span><span>    </span><span class="annot"><span class="annottext">RuleInfo -&gt; [CoreRule] -&gt; RuleInfo
</span><a href="GHC.Core.Rules.html#extendRuleInfo"><span class="hs-identifier hs-var">extendRuleInfo</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; RuleInfo
</span><a href="GHC.Types.Id.html#idSpecialisation"><span class="hs-identifier hs-var">idSpecialisation</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964502"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964501"><span class="hs-identifier hs-var">rules</span></a></span><span>
</span><span id="line-298"></span><span>
</span><span id="line-299"></span><span class="hs-comment">-- | Gather all the rules for locally bound identifiers from the supplied bindings</span><span>
</span><span id="line-300"></span><span class="annot"><a href="GHC.Core.Rules.html#rulesOfBinds"><span class="hs-identifier hs-type">rulesOfBinds</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreBind"><span class="hs-identifier hs-type">CoreBind</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-301"></span><span id="rulesOfBinds"><span class="annot"><span class="annottext">rulesOfBinds :: [CoreBind] -&gt; [CoreRule]
</span><a href="GHC.Core.Rules.html#rulesOfBinds"><span class="hs-identifier hs-var hs-var">rulesOfBinds</span></a></span></span><span> </span><span id="local-6989586621680964497"><span class="annot"><span class="annottext">[CoreBind]
</span><a href="#local-6989586621680964497"><span class="hs-identifier hs-var">binds</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreBind -&gt; [CoreRule]) -&gt; [CoreBind] -&gt; [CoreRule]
forall (t :: * -&gt; *) a b. Foldable t =&gt; (a -&gt; [b]) -&gt; t a -&gt; [b]
</span><a href="../../base/src/Data.Foldable.html#concatMap"><span class="hs-identifier hs-var">concatMap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Var -&gt; [CoreRule]) -&gt; [Var] -&gt; [CoreRule]
forall (t :: * -&gt; *) a b. Foldable t =&gt; (a -&gt; [b]) -&gt; t a -&gt; [b]
</span><a href="../../base/src/Data.Foldable.html#concatMap"><span class="hs-identifier hs-var">concatMap</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; [CoreRule]
</span><a href="GHC.Types.Id.html#idCoreRules"><span class="hs-identifier hs-var">idCoreRules</span></a></span><span> </span><span class="annot"><span class="annottext">([Var] -&gt; [CoreRule])
-&gt; (CoreBind -&gt; [Var]) -&gt; CoreBind -&gt; [CoreRule]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind -&gt; [Var]
forall b. Bind b -&gt; [b]
</span><a href="GHC.Core.html#bindersOf"><span class="hs-identifier hs-var">bindersOf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[CoreBind]
</span><a href="#local-6989586621680964497"><span class="hs-identifier hs-var">binds</span></a></span><span>
</span><span id="line-302"></span><span>
</span><span id="line-303"></span><span class="annot"><a href="GHC.Core.Rules.html#getRules"><span class="hs-identifier hs-type">getRules</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleEnv"><span class="hs-identifier hs-type">RuleEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-304"></span><span class="hs-comment">-- See Note [Where rules are found]</span><span>
</span><span id="line-305"></span><span id="getRules"><span class="annot"><span class="annottext">getRules :: RuleEnv -&gt; Var -&gt; [CoreRule]
</span><a href="GHC.Core.Rules.html#getRules"><span class="hs-identifier hs-var hs-var">getRules</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#RuleEnv"><span class="hs-identifier hs-type">RuleEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">re_base :: RuleEnv -&gt; RuleBase
</span><a href="GHC.Core.html#re_base"><span class="hs-identifier hs-var">re_base</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964490"><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964490"><span class="hs-identifier hs-var">rule_base</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">re_visible_orphs :: RuleEnv -&gt; ModuleSet
</span><a href="GHC.Core.html#re_visible_orphs"><span class="hs-identifier hs-var">re_visible_orphs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964488"><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621680964488"><span class="hs-identifier hs-var">orphs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span id="local-6989586621680964487"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964487"><span class="hs-identifier hs-var">fn</span></a></span></span><span>
</span><span id="line-306"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; [CoreRule]
</span><a href="GHC.Types.Id.html#idCoreRules"><span class="hs-identifier hs-var">idCoreRules</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964487"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; [CoreRule] -&gt; [CoreRule]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreRule -&gt; Bool) -&gt; [CoreRule] -&gt; [CoreRule]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ModuleSet -&gt; CoreRule -&gt; Bool
</span><a href="GHC.Core.Rules.html#ruleIsVisible"><span class="hs-identifier hs-var">ruleIsVisible</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621680964488"><span class="hs-identifier hs-var">orphs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964485"><span class="hs-identifier hs-var">imp_rules</span></a></span><span>
</span><span id="line-307"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-308"></span><span>    </span><span id="local-6989586621680964485"><span class="annot"><span class="annottext">imp_rules :: [CoreRule]
</span><a href="#local-6989586621680964485"><span class="hs-identifier hs-var hs-var">imp_rules</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleBase -&gt; Name -&gt; Maybe [CoreRule]
forall a. NameEnv a -&gt; Name -&gt; Maybe a
</span><a href="GHC.Types.Name.Env.html#lookupNameEnv"><span class="hs-identifier hs-var">lookupNameEnv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964490"><span class="hs-identifier hs-var">rule_base</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Name
</span><a href="GHC.Types.Id.html#idName"><span class="hs-identifier hs-var">idName</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964487"><span class="hs-identifier hs-var">fn</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe [CoreRule] -&gt; [CoreRule] -&gt; [CoreRule]
forall a. Maybe a -&gt; a -&gt; a
</span><a href="GHC.Data.Maybe.html#orElse"><span class="hs-operator hs-var">`orElse`</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-309"></span><span>
</span><span id="line-310"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleIsVisible"><span class="hs-identifier hs-type">ruleIsVisible</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Unit.Module.Env.html#ModuleSet"><span class="hs-identifier hs-type">ModuleSet</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-311"></span><span id="ruleIsVisible"><span class="annot"><span class="annottext">ruleIsVisible :: ModuleSet -&gt; CoreRule -&gt; Bool
</span><a href="GHC.Core.Rules.html#ruleIsVisible"><span class="hs-identifier hs-var hs-var">ruleIsVisible</span></a></span></span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><a href="GHC.Core.html#BuiltinRule"><span class="hs-identifier hs-type">BuiltinRule</span></a></span><span class="hs-special">{</span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-312"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleIsVisible"><span class="hs-identifier hs-var">ruleIsVisible</span></a></span><span> </span><span id="local-6989586621680964481"><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621680964481"><span class="hs-identifier hs-var">vis_orphs</span></a></span></span><span> </span><span class="annot"><a href="GHC.Core.html#Rule"><span class="hs-identifier hs-type">Rule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_orphan :: CoreRule -&gt; IsOrphan
</span><a href="GHC.Core.html#ru_orphan"><span class="hs-identifier hs-var">ru_orphan</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964480"><span class="annot"><span class="annottext">IsOrphan
</span><a href="#local-6989586621680964480"><span class="hs-identifier hs-var">orph</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_origin :: CoreRule -&gt; Module
</span><a href="GHC.Core.html#ru_origin"><span class="hs-identifier hs-var">ru_origin</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964479"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680964479"><span class="hs-identifier hs-var">origin</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-313"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IsOrphan -&gt; Bool
</span><a href="GHC.Core.html#notOrphan"><span class="hs-identifier hs-var">notOrphan</span></a></span><span> </span><span class="annot"><span class="annottext">IsOrphan
</span><a href="#local-6989586621680964480"><span class="hs-identifier hs-var">orph</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680964479"><span class="hs-identifier hs-var">origin</span></a></span><span> </span><span class="annot"><span class="annottext">Module -&gt; ModuleSet -&gt; Bool
</span><a href="GHC.Unit.Module.Env.html#elemModuleSet"><span class="hs-operator hs-var">`elemModuleSet`</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621680964481"><span class="hs-identifier hs-var">vis_orphs</span></a></span><span>
</span><span id="line-314"></span><span>
</span><span id="line-315"></span><span class="hs-comment">{- Note [Where rules are found]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The rules for an Id come from two places:
  (a) the ones it is born with, stored inside the Id itself (idCoreRules fn),
  (b) rules added in other modules, stored in the global RuleBase (imp_rules)

It's tempting to think that
     - LocalIds have only (a)
     - non-LocalIds have only (b)

but that isn't quite right:

     - PrimOps and ClassOps are born with a bunch of rules inside the Id,
       even when they are imported

     - The rules in GHC.Core.Opt.ConstantFold.builtinRules should be active even
       in the module defining the Id (when it's a LocalId), but
       the rules are kept in the global RuleBase


************************************************************************
*                                                                      *
                RuleBase
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-341"></span><span>
</span><span id="line-342"></span><span class="hs-comment">-- RuleBase itself is defined in GHC.Core, along with CoreRule</span><span>
</span><span id="line-343"></span><span>
</span><span id="line-344"></span><span class="annot"><a href="GHC.Core.Rules.html#emptyRuleBase"><span class="hs-identifier hs-type">emptyRuleBase</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span>
</span><span id="line-345"></span><span id="emptyRuleBase"><span class="annot"><span class="annottext">emptyRuleBase :: RuleBase
</span><a href="GHC.Core.Rules.html#emptyRuleBase"><span class="hs-identifier hs-var hs-var">emptyRuleBase</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleBase
forall a. NameEnv a
</span><a href="GHC.Types.Name.Env.html#emptyNameEnv"><span class="hs-identifier hs-var">emptyNameEnv</span></a></span><span>
</span><span id="line-346"></span><span>
</span><span id="line-347"></span><span class="annot"><a href="GHC.Core.Rules.html#mkRuleBase"><span class="hs-identifier hs-type">mkRuleBase</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span>
</span><span id="line-348"></span><span id="mkRuleBase"><span class="annot"><span class="annottext">mkRuleBase :: [CoreRule] -&gt; RuleBase
</span><a href="GHC.Core.Rules.html#mkRuleBase"><span class="hs-identifier hs-var hs-var">mkRuleBase</span></a></span></span><span> </span><span id="local-6989586621680964475"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964475"><span class="hs-identifier hs-var">rules</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleBase -&gt; [CoreRule] -&gt; RuleBase
</span><a href="GHC.Core.Rules.html#extendRuleBaseList"><span class="hs-identifier hs-var">extendRuleBaseList</span></a></span><span> </span><span class="annot"><span class="annottext">RuleBase
</span><a href="GHC.Core.Rules.html#emptyRuleBase"><span class="hs-identifier hs-var">emptyRuleBase</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964475"><span class="hs-identifier hs-var">rules</span></a></span><span>
</span><span id="line-349"></span><span>
</span><span id="line-350"></span><span class="annot"><a href="GHC.Core.Rules.html#extendRuleBaseList"><span class="hs-identifier hs-type">extendRuleBaseList</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span>
</span><span id="line-351"></span><span id="extendRuleBaseList"><span class="annot"><span class="annottext">extendRuleBaseList :: RuleBase -&gt; [CoreRule] -&gt; RuleBase
</span><a href="GHC.Core.Rules.html#extendRuleBaseList"><span class="hs-identifier hs-var hs-var">extendRuleBaseList</span></a></span></span><span> </span><span id="local-6989586621680964474"><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964474"><span class="hs-identifier hs-var">rule_base</span></a></span></span><span> </span><span id="local-6989586621680964473"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964473"><span class="hs-identifier hs-var">new_guys</span></a></span></span><span>
</span><span id="line-352"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(RuleBase -&gt; CoreRule -&gt; RuleBase)
-&gt; RuleBase -&gt; [CoreRule] -&gt; RuleBase
forall (t :: * -&gt; *) b a.
Foldable t =&gt;
(b -&gt; a -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldl%27"><span class="hs-identifier hs-var">foldl'</span></a></span><span> </span><span class="annot"><span class="annottext">RuleBase -&gt; CoreRule -&gt; RuleBase
</span><a href="GHC.Core.Rules.html#extendRuleBase"><span class="hs-identifier hs-var">extendRuleBase</span></a></span><span> </span><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964474"><span class="hs-identifier hs-var">rule_base</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964473"><span class="hs-identifier hs-var">new_guys</span></a></span><span>
</span><span id="line-353"></span><span>
</span><span id="line-354"></span><span class="annot"><a href="GHC.Core.Rules.html#unionRuleBase"><span class="hs-identifier hs-type">unionRuleBase</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span>
</span><span id="line-355"></span><span id="unionRuleBase"><span class="annot"><span class="annottext">unionRuleBase :: RuleBase -&gt; RuleBase -&gt; RuleBase
</span><a href="GHC.Core.Rules.html#unionRuleBase"><span class="hs-identifier hs-var hs-var">unionRuleBase</span></a></span></span><span> </span><span id="local-6989586621680964470"><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964470"><span class="hs-identifier hs-var">rb1</span></a></span></span><span> </span><span id="local-6989586621680964469"><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964469"><span class="hs-identifier hs-var">rb2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([CoreRule] -&gt; [CoreRule] -&gt; [CoreRule])
-&gt; RuleBase -&gt; RuleBase -&gt; RuleBase
forall a. (a -&gt; a -&gt; a) -&gt; NameEnv a -&gt; NameEnv a -&gt; NameEnv a
</span><a href="GHC.Types.Name.Env.html#plusNameEnv_C"><span class="hs-identifier hs-var">plusNameEnv_C</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; [CoreRule] -&gt; [CoreRule]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">(++)</span></a></span><span> </span><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964470"><span class="hs-identifier hs-var">rb1</span></a></span><span> </span><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964469"><span class="hs-identifier hs-var">rb2</span></a></span><span>
</span><span id="line-356"></span><span>
</span><span id="line-357"></span><span class="annot"><a href="GHC.Core.Rules.html#extendRuleBase"><span class="hs-identifier hs-type">extendRuleBase</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span>
</span><span id="line-358"></span><span id="extendRuleBase"><span class="annot"><span class="annottext">extendRuleBase :: RuleBase -&gt; CoreRule -&gt; RuleBase
</span><a href="GHC.Core.Rules.html#extendRuleBase"><span class="hs-identifier hs-var hs-var">extendRuleBase</span></a></span></span><span> </span><span id="local-6989586621680964467"><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964467"><span class="hs-identifier hs-var">rule_base</span></a></span></span><span> </span><span id="local-6989586621680964466"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964466"><span class="hs-identifier hs-var">rule</span></a></span></span><span>
</span><span id="line-359"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreRule -&gt; [CoreRule] -&gt; [CoreRule])
-&gt; (CoreRule -&gt; [CoreRule])
-&gt; RuleBase
-&gt; Name
-&gt; CoreRule
-&gt; RuleBase
forall a b.
(a -&gt; b -&gt; b) -&gt; (a -&gt; b) -&gt; NameEnv b -&gt; Name -&gt; a -&gt; NameEnv b
</span><a href="GHC.Types.Name.Env.html#extendNameEnv_Acc"><span class="hs-identifier hs-var">extendNameEnv_Acc</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">:</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; [CoreRule]
forall a. a -&gt; [a]
</span><a href="GHC.Utils.Misc.html#singleton"><span class="hs-identifier hs-var">Utils.singleton</span></a></span><span> </span><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964467"><span class="hs-identifier hs-var">rule_base</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule -&gt; Name
</span><a href="GHC.Core.html#ruleIdName"><span class="hs-identifier hs-var">ruleIdName</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964466"><span class="hs-identifier hs-var">rule</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964466"><span class="hs-identifier hs-var">rule</span></a></span><span>
</span><span id="line-360"></span><span>
</span><span id="line-361"></span><span class="annot"><a href="GHC.Core.Rules.html#pprRuleBase"><span class="hs-identifier hs-type">pprRuleBase</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleBase"><span class="hs-identifier hs-type">RuleBase</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-362"></span><span id="pprRuleBase"><span class="annot"><span class="annottext">pprRuleBase :: RuleBase -&gt; SDoc
</span><a href="GHC.Core.Rules.html#pprRuleBase"><span class="hs-identifier hs-var hs-var">pprRuleBase</span></a></span></span><span> </span><span id="local-6989586621680964462"><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964462"><span class="hs-identifier hs-var">rules</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleBase -&gt; ([[CoreRule]] -&gt; SDoc) -&gt; SDoc
forall key a. UniqFM key a -&gt; ([a] -&gt; SDoc) -&gt; SDoc
</span><a href="GHC.Types.Unique.FM.html#pprUFM"><span class="hs-identifier hs-var">pprUFM</span></a></span><span> </span><span class="annot"><span class="annottext">RuleBase
</span><a href="#local-6989586621680964462"><span class="hs-identifier hs-var">rules</span></a></span><span> </span><span class="annot"><span class="annottext">(([[CoreRule]] -&gt; SDoc) -&gt; SDoc) -&gt; ([[CoreRule]] -&gt; SDoc) -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621680964460"><span class="annot"><span class="annottext">[[CoreRule]]
</span><a href="#local-6989586621680964460"><span class="hs-identifier hs-var">rss</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-363"></span><span>  </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; SDoc
</span><a href="GHC.Core.Ppr.html#pprRules"><span class="hs-identifier hs-var">pprRules</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TidyEnv -&gt; [CoreRule] -&gt; [CoreRule]
</span><a href="GHC.Core.Tidy.html#tidyRules"><span class="hs-identifier hs-var">tidyRules</span></a></span><span> </span><span class="annot"><span class="annottext">TidyEnv
</span><a href="GHC.Types.Var.Env.html#emptyTidyEnv"><span class="hs-identifier hs-var">emptyTidyEnv</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964458"><span class="hs-identifier hs-var">rs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-364"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680964458"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964458"><span class="hs-identifier hs-var">rs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[[CoreRule]]
</span><a href="#local-6989586621680964460"><span class="hs-identifier hs-var">rss</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-365"></span><span>
</span><span id="line-366"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                        Matching
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-373"></span><span>
</span><span id="line-374"></span><span class="hs-comment">-- | The main rule matching function. Attempts to apply all (active)</span><span>
</span><span id="line-375"></span><span class="hs-comment">-- supplied rules to this instance of an application in a given</span><span>
</span><span id="line-376"></span><span class="hs-comment">-- context, returning the rule applied and the resulting expression if</span><span>
</span><span id="line-377"></span><span class="hs-comment">-- successful.</span><span>
</span><span id="line-378"></span><span class="annot"><a href="GHC.Core.Rules.html#lookupRule"><span class="hs-identifier hs-type">lookupRule</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleOpts"><span class="hs-identifier hs-type">RuleOpts</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#InScopeEnv"><span class="hs-identifier hs-type">InScopeEnv</span></a></span><span>
</span><span id="line-379"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Basic.html#Activation"><span class="hs-identifier hs-type">Activation</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">)</span><span>      </span><span class="hs-comment">-- When rule is active</span><span>
</span><span id="line-380"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-381"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-382"></span><span>
</span><span id="line-383"></span><span class="hs-comment">-- See Note [Extra args in rule matching]</span><span>
</span><span id="line-384"></span><span class="hs-comment">-- See comments on matchRule</span><span>
</span><span id="line-385"></span><span id="lookupRule"><span class="annot"><span class="annottext">lookupRule :: RuleOpts
-&gt; InScopeEnv
-&gt; (Activation -&gt; Bool)
-&gt; Var
-&gt; [CoreExpr]
-&gt; [CoreRule]
-&gt; Maybe (CoreRule, CoreExpr)
</span><a href="GHC.Core.Rules.html#lookupRule"><span class="hs-identifier hs-var hs-var">lookupRule</span></a></span></span><span> </span><span id="local-6989586621680964457"><span class="annot"><span class="annottext">RuleOpts
</span><a href="#local-6989586621680964457"><span class="hs-identifier hs-var">opts</span></a></span></span><span> </span><span id="local-6989586621680964456"><span class="annot"><span class="annottext">InScopeEnv
</span><a href="#local-6989586621680964456"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span> </span><span id="local-6989586621680964455"><span class="annot"><span class="annottext">Activation -&gt; Bool
</span><a href="#local-6989586621680964455"><span class="hs-identifier hs-var">is_active</span></a></span></span><span> </span><span id="local-6989586621680964454"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964454"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span id="local-6989586621680964453"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964453"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680964452"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964452"><span class="hs-identifier hs-var">rules</span></a></span></span><span>
</span><span id="line-386"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;matchRules&quot; (ppr fn &lt;+&gt; ppr args $$ ppr rules ) $</span><span>
</span><span id="line-387"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)] -&gt; [CoreRule] -&gt; [(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964451"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964452"><span class="hs-identifier hs-var">rules</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-388"></span><span>        </span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe (CoreRule, CoreExpr)
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-389"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680964450"><span class="annot"><span class="annottext">(CoreRule, CoreExpr)
</span><a href="#local-6989586621680964450"><span class="hs-identifier hs-var">m</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964449"><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964449"><span class="hs-identifier hs-var">ms</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(CoreRule, CoreExpr) -&gt; Maybe (CoreRule, CoreExpr)
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Var, [CoreExpr])
-&gt; (CoreRule, CoreExpr)
-&gt; [(CoreRule, CoreExpr)]
-&gt; (CoreRule, CoreExpr)
</span><a href="GHC.Core.Rules.html#findBest"><span class="hs-identifier hs-var">findBest</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964454"><span class="hs-identifier hs-var">fn</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964447"><span class="hs-identifier hs-var">args'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(CoreRule, CoreExpr)
</span><a href="#local-6989586621680964450"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964449"><span class="hs-identifier hs-var">ms</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-390"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-391"></span><span>    </span><span id="local-6989586621680964446"><span class="annot"><span class="annottext">rough_args :: [Maybe Name]
</span><a href="#local-6989586621680964446"><span class="hs-identifier hs-var hs-var">rough_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; Maybe Name) -&gt; [CoreExpr] -&gt; [Maybe Name]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Maybe Name
</span><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964453"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-392"></span><span>
</span><span id="line-393"></span><span>    </span><span class="hs-comment">-- Strip ticks from arguments, see note [Tick annotations in RULE</span><span>
</span><span id="line-394"></span><span>    </span><span class="hs-comment">-- matching]. We only collect ticks if a rule actually matches -</span><span>
</span><span id="line-395"></span><span>    </span><span class="hs-comment">-- this matters for performance tests.</span><span>
</span><span id="line-396"></span><span>    </span><span id="local-6989586621680964447"><span class="annot"><span class="annottext">args' :: [CoreExpr]
</span><a href="#local-6989586621680964447"><span class="hs-identifier hs-var hs-var">args'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; CoreExpr) -&gt; [CoreExpr] -&gt; [CoreExpr]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Tickish Var -&gt; Bool) -&gt; CoreExpr -&gt; CoreExpr
forall b. (Tickish Var -&gt; Bool) -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.Utils.html#stripTicksTopE"><span class="hs-identifier hs-var">stripTicksTopE</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964453"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-397"></span><span>    </span><span id="local-6989586621680964444"><span class="annot"><span class="annottext">ticks :: [Tickish Var]
</span><a href="#local-6989586621680964444"><span class="hs-identifier hs-var hs-var">ticks</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; [Tickish Var]) -&gt; [CoreExpr] -&gt; [Tickish Var]
forall (t :: * -&gt; *) a b. Foldable t =&gt; (a -&gt; [b]) -&gt; t a -&gt; [b]
</span><a href="../../base/src/Data.Foldable.html#concatMap"><span class="hs-identifier hs-var">concatMap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Tickish Var -&gt; Bool) -&gt; CoreExpr -&gt; [Tickish Var]
forall b. (Tickish Var -&gt; Bool) -&gt; Expr b -&gt; [Tickish Var]
</span><a href="GHC.Core.Utils.html#stripTicksTopT"><span class="hs-identifier hs-var">stripTicksTopT</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964453"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-398"></span><span>
</span><span id="line-399"></span><span>    </span><span class="annot"><a href="#local-6989586621680964451"><span class="hs-identifier hs-type">go</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-400"></span><span>    </span><span id="local-6989586621680964451"><span class="annot"><span class="annottext">go :: [(CoreRule, CoreExpr)] -&gt; [CoreRule] -&gt; [(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964451"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621680964443"><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964443"><span class="hs-identifier hs-var">ms</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964443"><span class="hs-identifier hs-var">ms</span></a></span><span>
</span><span id="line-401"></span><span>    </span><span class="annot"><a href="#local-6989586621680964451"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680964442"><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964442"><span class="hs-identifier hs-var">ms</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964441"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964441"><span class="hs-identifier hs-var">r</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964440"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964440"><span class="hs-identifier hs-var">rs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-402"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964439"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964439"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleOpts
-&gt; InScopeEnv
-&gt; (Activation -&gt; Bool)
-&gt; Var
-&gt; [CoreExpr]
-&gt; [Maybe Name]
-&gt; CoreRule
-&gt; Maybe CoreExpr
</span><a href="GHC.Core.Rules.html#matchRule"><span class="hs-identifier hs-var">matchRule</span></a></span><span> </span><span class="annot"><span class="annottext">RuleOpts
</span><a href="#local-6989586621680964457"><span class="hs-identifier hs-var">opts</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeEnv
</span><a href="#local-6989586621680964456"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">Activation -&gt; Bool
</span><a href="#local-6989586621680964455"><span class="hs-identifier hs-var">is_active</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964454"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964447"><span class="hs-identifier hs-var">args'</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964446"><span class="hs-identifier hs-var">rough_args</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964441"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-403"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)] -&gt; [CoreRule] -&gt; [(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964451"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964441"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[Tickish Var] -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Utils.html#mkTicks"><span class="hs-identifier hs-var">mkTicks</span></a></span><span> </span><span class="annot"><span class="annottext">[Tickish Var]
</span><a href="#local-6989586621680964444"><span class="hs-identifier hs-var">ticks</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964439"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span class="annot"><span class="annottext">(CoreRule, CoreExpr)
-&gt; [(CoreRule, CoreExpr)] -&gt; [(CoreRule, CoreExpr)]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964442"><span class="hs-identifier hs-var">ms</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964440"><span class="hs-identifier hs-var">rs</span></a></span><span>
</span><span id="line-404"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-405"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;match failed&quot; (ppr r $$ ppr args $$</span><span>
</span><span id="line-406"></span><span>        </span><span class="hs-comment">--   ppr [ (arg_id, unfoldingTemplate unf)</span><span>
</span><span id="line-407"></span><span>        </span><span class="hs-comment">--       | Var arg_id &lt;- args</span><span>
</span><span id="line-408"></span><span>        </span><span class="hs-comment">--       , let unf = idUnfolding arg_id</span><span>
</span><span id="line-409"></span><span>        </span><span class="hs-comment">--       , isCheapUnfolding unf] )</span><span>
</span><span id="line-410"></span><span>        </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)] -&gt; [CoreRule] -&gt; [(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964451"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964442"><span class="hs-identifier hs-var">ms</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680964440"><span class="hs-identifier hs-var">rs</span></a></span><span>
</span><span id="line-411"></span><span>
</span><span id="line-412"></span><span class="annot"><a href="GHC.Core.Rules.html#findBest"><span class="hs-identifier hs-type">findBest</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-413"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-414"></span><span class="hs-comment">-- All these pairs matched the expression</span><span>
</span><span id="line-415"></span><span class="hs-comment">-- Return the pair the most specific rule</span><span>
</span><span id="line-416"></span><span class="hs-comment">-- The (fn,args) is just for overlap reporting</span><span>
</span><span id="line-417"></span><span>
</span><span id="line-418"></span><span id="findBest"><span class="annot"><span class="annottext">findBest :: (Var, [CoreExpr])
-&gt; (CoreRule, CoreExpr)
-&gt; [(CoreRule, CoreExpr)]
-&gt; (CoreRule, CoreExpr)
</span><a href="GHC.Core.Rules.html#findBest"><span class="hs-identifier hs-var hs-var">findBest</span></a></span></span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621680964437"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964437"><span class="hs-identifier hs-var">rule</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964436"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964436"><span class="hs-identifier hs-var">ans</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964437"><span class="hs-identifier hs-var">rule</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964436"><span class="hs-identifier hs-var">ans</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-419"></span><span class="annot"><a href="GHC.Core.Rules.html#findBest"><span class="hs-identifier hs-var">findBest</span></a></span><span> </span><span id="local-6989586621680964435"><span class="annot"><span class="annottext">(Var, [CoreExpr])
</span><a href="#local-6989586621680964435"><span class="hs-identifier hs-var">target</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964434"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964434"><span class="hs-identifier hs-var">rule1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964433"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964433"><span class="hs-identifier hs-var">ans1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621680964432"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964432"><span class="hs-identifier hs-var">rule2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964431"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964431"><span class="hs-identifier hs-var">ans2</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964430"><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964430"><span class="hs-identifier hs-var">prs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-420"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964434"><span class="hs-identifier hs-var">rule1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; CoreRule -&gt; Bool
</span><a href="GHC.Core.Rules.html#isMoreSpecific"><span class="hs-operator hs-var">`isMoreSpecific`</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964432"><span class="hs-identifier hs-var">rule2</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
-&gt; (CoreRule, CoreExpr)
-&gt; [(CoreRule, CoreExpr)]
-&gt; (CoreRule, CoreExpr)
</span><a href="GHC.Core.Rules.html#findBest"><span class="hs-identifier hs-var">findBest</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
</span><a href="#local-6989586621680964435"><span class="hs-identifier hs-var">target</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964434"><span class="hs-identifier hs-var">rule1</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964433"><span class="hs-identifier hs-var">ans1</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964430"><span class="hs-identifier hs-var">prs</span></a></span><span>
</span><span id="line-421"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964432"><span class="hs-identifier hs-var">rule2</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; CoreRule -&gt; Bool
</span><a href="GHC.Core.Rules.html#isMoreSpecific"><span class="hs-operator hs-var">`isMoreSpecific`</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964434"><span class="hs-identifier hs-var">rule1</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
-&gt; (CoreRule, CoreExpr)
-&gt; [(CoreRule, CoreExpr)]
-&gt; (CoreRule, CoreExpr)
</span><a href="GHC.Core.Rules.html#findBest"><span class="hs-identifier hs-var">findBest</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
</span><a href="#local-6989586621680964435"><span class="hs-identifier hs-var">target</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964432"><span class="hs-identifier hs-var">rule2</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964431"><span class="hs-identifier hs-var">ans2</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964430"><span class="hs-identifier hs-var">prs</span></a></span><span>
</span><span id="line-422"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Utils.Misc.html#debugIsOn"><span class="hs-identifier hs-var">debugIsOn</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680964425"><span class="annot"><span class="annottext">pp_rule :: CoreRule -&gt; SDoc
</span><a href="#local-6989586621680964425"><span class="hs-identifier hs-var hs-var">pp_rule</span></a></span></span><span> </span><span id="local-6989586621680964424"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964424"><span class="hs-identifier hs-var">rule</span></a></span></span><span>
</span><span id="line-423"></span><span>                      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ifPprDebug"><span class="hs-identifier hs-var">ifPprDebug</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964424"><span class="hs-identifier hs-var">rule</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-424"></span><span>                                   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#doubleQuotes"><span class="hs-identifier hs-var">doubleQuotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleName -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ftext"><span class="hs-identifier hs-var">ftext</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule -&gt; RuleName
</span><a href="GHC.Core.html#ruleName"><span class="hs-identifier hs-var">ruleName</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964424"><span class="hs-identifier hs-var">rule</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-425"></span><span>                </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; (CoreRule, CoreExpr) -&gt; (CoreRule, CoreExpr)
forall a. String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprTrace"><span class="hs-identifier hs-var">pprTrace</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Rules.findBest: rule overlap (Rule 1 wins)&quot;</span></span><span>
</span><span id="line-426"></span><span>                         </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#whenPprDebug"><span class="hs-identifier hs-var">whenPprDebug</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; SDoc) -&gt; SDoc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-427"></span><span>                                 </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Expression to match:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964415"><span class="hs-identifier hs-var">fn</span></a></span><span>
</span><span id="line-428"></span><span>                                 </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(CoreExpr -&gt; SDoc) -&gt; [CoreExpr] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964413"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-429"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Rule 1:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; SDoc
</span><a href="#local-6989586621680964425"><span class="hs-identifier hs-var">pp_rule</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964434"><span class="hs-identifier hs-var">rule1</span></a></span><span>
</span><span id="line-430"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Rule 2:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; SDoc
</span><a href="#local-6989586621680964425"><span class="hs-identifier hs-var">pp_rule</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964432"><span class="hs-identifier hs-var">rule2</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((CoreRule, CoreExpr) -&gt; (CoreRule, CoreExpr))
-&gt; (CoreRule, CoreExpr) -&gt; (CoreRule, CoreExpr)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-431"></span><span>                </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
-&gt; (CoreRule, CoreExpr)
-&gt; [(CoreRule, CoreExpr)]
-&gt; (CoreRule, CoreExpr)
</span><a href="GHC.Core.Rules.html#findBest"><span class="hs-identifier hs-var">findBest</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
</span><a href="#local-6989586621680964435"><span class="hs-identifier hs-var">target</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964434"><span class="hs-identifier hs-var">rule1</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964433"><span class="hs-identifier hs-var">ans1</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964430"><span class="hs-identifier hs-var">prs</span></a></span><span>
</span><span id="line-432"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
-&gt; (CoreRule, CoreExpr)
-&gt; [(CoreRule, CoreExpr)]
-&gt; (CoreRule, CoreExpr)
</span><a href="GHC.Core.Rules.html#findBest"><span class="hs-identifier hs-var">findBest</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
</span><a href="#local-6989586621680964435"><span class="hs-identifier hs-var">target</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680964434"><span class="hs-identifier hs-var">rule1</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964433"><span class="hs-identifier hs-var">ans1</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(CoreRule, CoreExpr)]
</span><a href="#local-6989586621680964430"><span class="hs-identifier hs-var">prs</span></a></span><span>
</span><span id="line-433"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-434"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680964415"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964415"><span class="hs-identifier hs-var">fn</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964413"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964413"><span class="hs-identifier hs-var">args</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Var, [CoreExpr])
</span><a href="#local-6989586621680964435"><span class="hs-identifier hs-var">target</span></a></span><span>
</span><span id="line-435"></span><span>
</span><span id="line-436"></span><span class="annot"><a href="GHC.Core.Rules.html#isMoreSpecific"><span class="hs-identifier hs-type">isMoreSpecific</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-437"></span><span class="hs-comment">-- This tests if one rule is more specific than another</span><span>
</span><span id="line-438"></span><span class="hs-comment">-- We take the view that a BuiltinRule is less specific than</span><span>
</span><span id="line-439"></span><span class="hs-comment">-- anything else, because we want user-define rules to &quot;win&quot;</span><span>
</span><span id="line-440"></span><span class="hs-comment">-- In particular, class ops have a built-in rule, but we</span><span>
</span><span id="line-441"></span><span class="hs-comment">-- any user-specific rules to win</span><span>
</span><span id="line-442"></span><span class="hs-comment">--   eg (#4397)</span><span>
</span><span id="line-443"></span><span class="hs-comment">--      truncate :: (RealFrac a, Integral b) =&gt; a -&gt; b</span><span>
</span><span id="line-444"></span><span class="hs-comment">--      {-# RULES &quot;truncate/Double-&gt;Int&quot; truncate = double2Int #-}</span><span>
</span><span id="line-445"></span><span class="hs-comment">--      double2Int :: Double -&gt; Int</span><span>
</span><span id="line-446"></span><span class="hs-comment">--   We want the specific RULE to beat the built-in class-op rule</span><span>
</span><span id="line-447"></span><span id="isMoreSpecific"><span class="annot"><span class="annottext">isMoreSpecific :: CoreRule -&gt; CoreRule -&gt; Bool
</span><a href="GHC.Core.Rules.html#isMoreSpecific"><span class="hs-identifier hs-var hs-var">isMoreSpecific</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#BuiltinRule"><span class="hs-identifier hs-type">BuiltinRule</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><span class="hs-identifier">_</span></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-448"></span><span class="annot"><a href="GHC.Core.Rules.html#isMoreSpecific"><span class="hs-identifier hs-var">isMoreSpecific</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rule"><span class="hs-identifier hs-type">Rule</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#BuiltinRule"><span class="hs-identifier hs-type">BuiltinRule</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-449"></span><span class="annot"><a href="GHC.Core.Rules.html#isMoreSpecific"><span class="hs-identifier hs-var">isMoreSpecific</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rule"><span class="hs-identifier hs-type">Rule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_bndrs :: CoreRule -&gt; [Var]
</span><a href="GHC.Core.html#ru_bndrs"><span class="hs-identifier hs-var">ru_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964412"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964412"><span class="hs-identifier hs-var">bndrs1</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_args :: CoreRule -&gt; [CoreExpr]
</span><a href="GHC.Core.html#ru_args"><span class="hs-identifier hs-var">ru_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964411"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964411"><span class="hs-identifier hs-var">args1</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-450"></span><span>               </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rule"><span class="hs-identifier hs-type">Rule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_bndrs :: CoreRule -&gt; [Var]
</span><a href="GHC.Core.html#ru_bndrs"><span class="hs-identifier hs-var">ru_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964410"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964410"><span class="hs-identifier hs-var">bndrs2</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_args :: CoreRule -&gt; [CoreExpr]
</span><a href="GHC.Core.html#ru_args"><span class="hs-identifier hs-var">ru_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964409"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964409"><span class="hs-identifier hs-var">args2</span></a></span></span><span>
</span><span id="line-451"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_name :: CoreRule -&gt; RuleName
</span><a href="GHC.Core.html#ru_name"><span class="hs-identifier hs-var">ru_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964408"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680964408"><span class="hs-identifier hs-var">rule_name2</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_rhs :: CoreRule -&gt; CoreExpr
</span><a href="GHC.Core.html#ru_rhs"><span class="hs-identifier hs-var">ru_rhs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964407"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964407"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-452"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe CoreExpr -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InScopeEnv
-&gt; RuleName
-&gt; [Var]
-&gt; [CoreExpr]
-&gt; [CoreExpr]
-&gt; CoreExpr
-&gt; Maybe CoreExpr
</span><a href="GHC.Core.Rules.html#matchN"><span class="hs-identifier hs-var">matchN</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680964404"><span class="hs-identifier hs-var">in_scope</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Unfolding
forall {p}. p -&gt; Unfolding
</span><a href="#local-6989586621680964403"><span class="hs-identifier hs-var">id_unfolding_fun</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680964408"><span class="hs-identifier hs-var">rule_name2</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964410"><span class="hs-identifier hs-var">bndrs2</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964409"><span class="hs-identifier hs-var">args2</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964411"><span class="hs-identifier hs-var">args1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964407"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-453"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-454"></span><span>   </span><span id="local-6989586621680964403"><span class="annot"><span class="annottext">id_unfolding_fun :: p -&gt; Unfolding
</span><a href="#local-6989586621680964403"><span class="hs-identifier hs-var hs-var">id_unfolding_fun</span></a></span></span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="GHC.Core.html#NoUnfolding"><span class="hs-identifier hs-var">NoUnfolding</span></a></span><span>     </span><span class="hs-comment">-- Don't expand in templates</span><span>
</span><span id="line-455"></span><span>   </span><span id="local-6989586621680964404"><span class="annot"><span class="annottext">in_scope :: InScopeSet
</span><a href="#local-6989586621680964404"><span class="hs-identifier hs-var hs-var">in_scope</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; InScopeSet
</span><a href="GHC.Types.Var.Env.html#mkInScopeSet"><span class="hs-identifier hs-var">mkInScopeSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Var] -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964412"><span class="hs-identifier hs-var">bndrs1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-456"></span><span>        </span><span class="hs-comment">-- Actually we should probably include the free vars</span><span>
</span><span id="line-457"></span><span>        </span><span class="hs-comment">-- of rule1's args, but I can't be bothered</span><span>
</span><span id="line-458"></span><span>
</span><span id="line-459"></span><span class="annot"><a href="GHC.Core.Rules.html#noBlackList"><span class="hs-identifier hs-type">noBlackList</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Activation"><span class="hs-identifier hs-type">Activation</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-460"></span><span id="noBlackList"><span class="annot"><span class="annottext">noBlackList :: Activation -&gt; Bool
</span><a href="GHC.Core.Rules.html#noBlackList"><span class="hs-identifier hs-var hs-var">noBlackList</span></a></span></span><span> </span><span class="annot"><span class="annottext">Activation
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>           </span><span class="hs-comment">-- Nothing is black listed</span><span>
</span><span id="line-461"></span><span>
</span><span id="line-462"></span><span class="hs-comment">{-
Note [Extra args in rule matching]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If we find a matching rule, we return (Just (rule, rhs)),
but the rule firing has only consumed as many of the input args
as the ruleArity says.  It's up to the caller to keep track
of any left-over args.  E.g. if you call
        lookupRule ... f [e1, e2, e3]
and it returns Just (r, rhs), where r has ruleArity 2
then the real rewrite is
        f e1 e2 e3 ==&gt; rhs e3

You might think it'd be cleaner for lookupRule to deal with the
leftover arguments, by applying 'rhs' to them, but the main call
in the Simplifier works better as it is.  Reason: the 'args' passed
to lookupRule are the result of a lazy substitution
-}</span><span>
</span><span id="line-479"></span><span>
</span><span id="line-480"></span><span class="hs-comment">------------------------------------</span><span>
</span><span id="line-481"></span><span class="annot"><a href="GHC.Core.Rules.html#matchRule"><span class="hs-identifier hs-type">matchRule</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleOpts"><span class="hs-identifier hs-type">RuleOpts</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#InScopeEnv"><span class="hs-identifier hs-type">InScopeEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Basic.html#Activation"><span class="hs-identifier hs-type">Activation</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">)</span><span>
</span><span id="line-482"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-483"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-484"></span><span>
</span><span id="line-485"></span><span class="hs-comment">-- If (matchRule rule args) returns Just (name,rhs)</span><span>
</span><span id="line-486"></span><span class="hs-comment">-- then (f args) matches the rule, and the corresponding</span><span>
</span><span id="line-487"></span><span class="hs-comment">-- rewritten RHS is rhs</span><span>
</span><span id="line-488"></span><span class="hs-comment">--</span><span>
</span><span id="line-489"></span><span class="hs-comment">-- The returned expression is occurrence-analysed</span><span>
</span><span id="line-490"></span><span class="hs-comment">--</span><span>
</span><span id="line-491"></span><span class="hs-comment">--      Example</span><span>
</span><span id="line-492"></span><span class="hs-comment">--</span><span>
</span><span id="line-493"></span><span class="hs-comment">-- The rule</span><span>
</span><span id="line-494"></span><span class="hs-comment">--      forall f g x. map f (map g x) ==&gt; map (f . g) x</span><span>
</span><span id="line-495"></span><span class="hs-comment">-- is stored</span><span>
</span><span id="line-496"></span><span class="hs-comment">--      CoreRule &quot;map/map&quot;</span><span>
</span><span id="line-497"></span><span class="hs-comment">--               [f,g,x]                -- tpl_vars</span><span>
</span><span id="line-498"></span><span class="hs-comment">--               [f,map g x]            -- tpl_args</span><span>
</span><span id="line-499"></span><span class="hs-comment">--               map (f.g) x)           -- rhs</span><span>
</span><span id="line-500"></span><span class="hs-comment">--</span><span>
</span><span id="line-501"></span><span class="hs-comment">-- Then the call: matchRule the_rule [e1,map e2 e3]</span><span>
</span><span id="line-502"></span><span class="hs-comment">--        = Just (&quot;map/map&quot;, (\f,g,x -&gt; rhs) e1 e2 e3)</span><span>
</span><span id="line-503"></span><span class="hs-comment">--</span><span>
</span><span id="line-504"></span><span class="hs-comment">-- Any 'surplus' arguments in the input are simply put on the end</span><span>
</span><span id="line-505"></span><span class="hs-comment">-- of the output.</span><span>
</span><span id="line-506"></span><span>
</span><span id="line-507"></span><span id="matchRule"><span class="annot"><span class="annottext">matchRule :: RuleOpts
-&gt; InScopeEnv
-&gt; (Activation -&gt; Bool)
-&gt; Var
-&gt; [CoreExpr]
-&gt; [Maybe Name]
-&gt; CoreRule
-&gt; Maybe CoreExpr
</span><a href="GHC.Core.Rules.html#matchRule"><span class="hs-identifier hs-var hs-var">matchRule</span></a></span></span><span> </span><span id="local-6989586621680964398"><span class="annot"><span class="annottext">RuleOpts
</span><a href="#local-6989586621680964398"><span class="hs-identifier hs-var">opts</span></a></span></span><span> </span><span id="local-6989586621680964397"><span class="annot"><span class="annottext">InScopeEnv
</span><a href="#local-6989586621680964397"><span class="hs-identifier hs-var">rule_env</span></a></span></span><span> </span><span id="local-6989586621680964396"><span class="annot"><span class="annottext">Activation -&gt; Bool
</span><a href="#local-6989586621680964396"><span class="hs-identifier hs-var">_is_active</span></a></span></span><span> </span><span id="local-6989586621680964395"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964395"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span id="local-6989586621680964394"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964394"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680964393"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964393"><span class="hs-identifier hs-var">_rough_args</span></a></span></span><span>
</span><span id="line-508"></span><span>          </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#BuiltinRule"><span class="hs-identifier hs-type">BuiltinRule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_try :: CoreRule -&gt; RuleFun
</span><a href="GHC.Core.html#ru_try"><span class="hs-identifier hs-var">ru_try</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964391"><span class="annot"><span class="annottext">RuleFun
</span><a href="#local-6989586621680964391"><span class="hs-identifier hs-var">match_fn</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-509"></span><span class="hs-comment">-- Built-in rules can't be switched off, it seems</span><span>
</span><span id="line-510"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">RuleFun
</span><a href="#local-6989586621680964391"><span class="hs-identifier hs-var">match_fn</span></a></span><span> </span><span class="annot"><span class="annottext">RuleOpts
</span><a href="#local-6989586621680964398"><span class="hs-identifier hs-var">opts</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeEnv
</span><a href="#local-6989586621680964397"><span class="hs-identifier hs-var">rule_env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964395"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964394"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-511"></span><span>        </span><span class="annot"><span class="annottext">Maybe CoreExpr
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe CoreExpr
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-512"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964390"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964390"><span class="hs-identifier hs-var">expr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Maybe CoreExpr
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964390"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-513"></span><span>
</span><span id="line-514"></span><span class="annot"><a href="GHC.Core.Rules.html#matchRule"><span class="hs-identifier hs-var">matchRule</span></a></span><span> </span><span class="annot"><span class="annottext">RuleOpts
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964389"><span class="annot"><span class="annottext">InScopeEnv
</span><a href="#local-6989586621680964389"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span> </span><span id="local-6989586621680964388"><span class="annot"><span class="annottext">Activation -&gt; Bool
</span><a href="#local-6989586621680964388"><span class="hs-identifier hs-var">is_active</span></a></span></span><span> </span><span class="annot"><span class="annottext">Var
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964387"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964387"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680964386"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964386"><span class="hs-identifier hs-var">rough_args</span></a></span></span><span>
</span><span id="line-515"></span><span>          </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rule"><span class="hs-identifier hs-type">Rule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_name :: CoreRule -&gt; RuleName
</span><a href="GHC.Core.html#ru_name"><span class="hs-identifier hs-var">ru_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964385"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680964385"><span class="hs-identifier hs-var">rule_name</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_act :: CoreRule -&gt; Activation
</span><a href="GHC.Core.html#ru_act"><span class="hs-identifier hs-var">ru_act</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964384"><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680964384"><span class="hs-identifier hs-var">act</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_rough :: CoreRule -&gt; [Maybe Name]
</span><a href="GHC.Core.html#ru_rough"><span class="hs-identifier hs-var">ru_rough</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964383"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964383"><span class="hs-identifier hs-var">tpl_tops</span></a></span></span><span>
</span><span id="line-516"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_bndrs :: CoreRule -&gt; [Var]
</span><a href="GHC.Core.html#ru_bndrs"><span class="hs-identifier hs-var">ru_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964382"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964382"><span class="hs-identifier hs-var">tpl_vars</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_args :: CoreRule -&gt; [CoreExpr]
</span><a href="GHC.Core.html#ru_args"><span class="hs-identifier hs-var">ru_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964381"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964381"><span class="hs-identifier hs-var">tpl_args</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_rhs :: CoreRule -&gt; CoreExpr
</span><a href="GHC.Core.html#ru_rhs"><span class="hs-identifier hs-var">ru_rhs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964380"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964380"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-517"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Activation -&gt; Bool
</span><a href="#local-6989586621680964388"><span class="hs-identifier hs-var">is_active</span></a></span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680964384"><span class="hs-identifier hs-var">act</span></a></span><span class="hs-special">)</span><span>               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe CoreExpr
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-518"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[Maybe Name] -&gt; [Maybe Name] -&gt; Bool
</span><a href="GHC.Core.Rules.html#ruleCantMatch"><span class="hs-identifier hs-var">ruleCantMatch</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964383"><span class="hs-identifier hs-var">tpl_tops</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680964386"><span class="hs-identifier hs-var">rough_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe CoreExpr
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-519"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeEnv
-&gt; RuleName
-&gt; [Var]
-&gt; [CoreExpr]
-&gt; [CoreExpr]
-&gt; CoreExpr
-&gt; Maybe CoreExpr
</span><a href="GHC.Core.Rules.html#matchN"><span class="hs-identifier hs-var">matchN</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeEnv
</span><a href="#local-6989586621680964389"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680964385"><span class="hs-identifier hs-var">rule_name</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964382"><span class="hs-identifier hs-var">tpl_vars</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964381"><span class="hs-identifier hs-var">tpl_args</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964387"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964380"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-520"></span><span>
</span><span id="line-521"></span><span>
</span><span id="line-522"></span><span class="hs-comment">-- | Initialize RuleOpts from DynFlags</span><span>
</span><span id="line-523"></span><span class="annot"><a href="GHC.Core.Rules.html#initRuleOpts"><span class="hs-identifier hs-type">initRuleOpts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleOpts"><span class="hs-identifier hs-type">RuleOpts</span></a></span><span>
</span><span id="line-524"></span><span id="initRuleOpts"><span class="annot"><span class="annottext">initRuleOpts :: DynFlags -&gt; RuleOpts
</span><a href="GHC.Core.Rules.html#initRuleOpts"><span class="hs-identifier hs-var hs-var">initRuleOpts</span></a></span></span><span> </span><span id="local-6989586621680964378"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680964378"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleOpts :: Platform -&gt; Bool -&gt; Bool -&gt; RuleOpts
</span><a href="GHC.Core.html#RuleOpts"><span class="hs-identifier hs-type">RuleOpts</span></a></span><span>
</span><span id="line-525"></span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">roPlatform :: Platform
</span><a href="GHC.Core.html#roPlatform"><span class="hs-identifier hs-var">roPlatform</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Platform
</span><a href="GHC.Driver.Session.html#targetPlatform"><span class="hs-identifier hs-var hs-var">targetPlatform</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680964378"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-526"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">roNumConstantFolding :: Bool
</span><a href="GHC.Core.html#roNumConstantFolding"><span class="hs-identifier hs-var">roNumConstantFolding</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_NumConstantFolding"><span class="hs-identifier hs-var">Opt_NumConstantFolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680964378"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-527"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">roExcessRationalPrecision :: Bool
</span><a href="GHC.Core.html#roExcessRationalPrecision"><span class="hs-identifier hs-var">roExcessRationalPrecision</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_ExcessPrecision"><span class="hs-identifier hs-var">Opt_ExcessPrecision</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680964378"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-528"></span><span>  </span><span class="hs-special">}</span><span>
</span><span id="line-529"></span><span>
</span><span id="line-530"></span><span>
</span><span id="line-531"></span><span class="hs-comment">---------------------------------------</span><span>
</span><span id="line-532"></span><span class="annot"><a href="GHC.Core.Rules.html#matchN"><span class="hs-identifier hs-type">matchN</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#InScopeEnv"><span class="hs-identifier hs-type">InScopeEnv</span></a></span><span>
</span><span id="line-533"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#RuleName"><span class="hs-identifier hs-type">RuleName</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-534"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>           </span><span class="hs-comment">-- ^ Target; can have more elements than the template</span><span>
</span><span id="line-535"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-536"></span><span class="hs-comment">-- For a given match template and context, find bindings to wrap around</span><span>
</span><span id="line-537"></span><span class="hs-comment">-- the entire result and what should be substituted for each template variable.</span><span>
</span><span id="line-538"></span><span class="hs-comment">-- Fail if there are two few actual arguments from the target to match the template</span><span>
</span><span id="line-539"></span><span>
</span><span id="line-540"></span><span id="matchN"><span class="annot"><span class="annottext">matchN :: InScopeEnv
-&gt; RuleName
-&gt; [Var]
-&gt; [CoreExpr]
-&gt; [CoreExpr]
-&gt; CoreExpr
-&gt; Maybe CoreExpr
</span><a href="GHC.Core.Rules.html#matchN"><span class="hs-identifier hs-var hs-var">matchN</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964371"><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680964371"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964370"><span class="annot"><span class="annottext">Var -&gt; Unfolding
</span><a href="#local-6989586621680964370"><span class="hs-identifier hs-var">id_unf</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680964369"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680964369"><span class="hs-identifier hs-var">rule_name</span></a></span></span><span> </span><span id="local-6989586621680964368"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964368"><span class="hs-identifier hs-var">tmpl_vars</span></a></span></span><span> </span><span id="local-6989586621680964367"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964367"><span class="hs-identifier hs-var">tmpl_es</span></a></span></span><span> </span><span id="local-6989586621680964366"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964366"><span class="hs-identifier hs-var">target_es</span></a></span></span><span> </span><span id="local-6989586621680964365"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964365"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-541"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964364"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964364"><span class="hs-identifier hs-var">rule_subst</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; [CoreExpr] -&gt; [CoreExpr] -&gt; Maybe RuleSubst
</span><a href="#local-6989586621680964363"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964362"><span class="hs-identifier hs-var">init_menv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="GHC.Core.Rules.html#emptyRuleSubst"><span class="hs-identifier hs-var">emptyRuleSubst</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964367"><span class="hs-identifier hs-var">tmpl_es</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964366"><span class="hs-identifier hs-var">target_es</span></a></span><span>
</span><span id="line-542"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964358"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964358"><span class="hs-identifier hs-var">matched_es</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TCvSubst -&gt; (Var, Var) -&gt; (TCvSubst, CoreExpr))
-&gt; TCvSubst -&gt; [(Var, Var)] -&gt; (TCvSubst, [CoreExpr])
forall (t :: * -&gt; *) s a b.
Traversable t =&gt;
(s -&gt; a -&gt; (s, b)) -&gt; s -&gt; t a -&gt; (s, t b)
</span><a href="../../base/src/Data.Traversable.html#mapAccumL"><span class="hs-identifier hs-var">mapAccumL</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleSubst -&gt; TCvSubst -&gt; (Var, Var) -&gt; (TCvSubst, CoreExpr)
</span><a href="#local-6989586621680964356"><span class="hs-identifier hs-var">lookup_tmpl</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964364"><span class="hs-identifier hs-var">rule_subst</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-543"></span><span>                                          </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InScopeSet -&gt; TCvSubst
</span><a href="GHC.Core.TyCo.Subst.html#mkEmptyTCvSubst"><span class="hs-identifier hs-var">mkEmptyTCvSubst</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680964371"><span class="hs-identifier hs-var">in_scope</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([(Var, Var)] -&gt; (TCvSubst, [CoreExpr]))
-&gt; [(Var, Var)] -&gt; (TCvSubst, [CoreExpr])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-544"></span><span>                                </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964368"><span class="hs-identifier hs-var">tmpl_vars</span></a></span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; [Var] -&gt; [(Var, Var)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-operator hs-var">`zip`</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964355"><span class="hs-identifier hs-var">tmpl_vars1</span></a></span><span>
</span><span id="line-545"></span><span>              </span><span id="local-6989586621680964354"><span class="annot"><span class="annottext">bind_wrapper :: CoreExpr -&gt; CoreExpr
</span><a href="#local-6989586621680964354"><span class="hs-identifier hs-var hs-var">bind_wrapper</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var hs-var">rs_binds</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964364"><span class="hs-identifier hs-var">rule_subst</span></a></span><span>
</span><span id="line-546"></span><span>                             </span><span class="hs-comment">-- Floated bindings; see Note [Matching lets]</span><span>
</span><span id="line-547"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Maybe CoreExpr
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; CoreExpr
</span><a href="#local-6989586621680964354"><span class="hs-identifier hs-var">bind_wrapper</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; CoreExpr) -&gt; CoreExpr -&gt; CoreExpr
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-548"></span><span>                 </span><span class="annot"><span class="annottext">[Var] -&gt; CoreExpr -&gt; CoreExpr
forall b. [b] -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#mkLams"><span class="hs-identifier hs-var">mkLams</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964368"><span class="hs-identifier hs-var">tmpl_vars</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964365"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; [CoreExpr] -&gt; CoreExpr
forall b. Expr b -&gt; [Expr b] -&gt; Expr b
</span><a href="GHC.Core.html#mkApps"><span class="hs-operator hs-var">`mkApps`</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964358"><span class="hs-identifier hs-var">matched_es</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-549"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-550"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680964349"><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964349"><span class="hs-identifier hs-var">init_rn_env</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964355"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964355"><span class="hs-identifier hs-var">tmpl_vars1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(RnEnv2 -&gt; Var -&gt; (RnEnv2, Var))
-&gt; RnEnv2 -&gt; [Var] -&gt; (RnEnv2, [Var])
forall (t :: * -&gt; *) s a b.
Traversable t =&gt;
(s -&gt; a -&gt; (s, b)) -&gt; s -&gt; t a -&gt; (s, t b)
</span><a href="../../base/src/Data.Traversable.html#mapAccumL"><span class="hs-identifier hs-var">mapAccumL</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; (RnEnv2, Var)
</span><a href="GHC.Types.Var.Env.html#rnBndrL"><span class="hs-identifier hs-var">rnBndrL</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InScopeSet -&gt; RnEnv2
</span><a href="GHC.Types.Var.Env.html#mkRnEnv2"><span class="hs-identifier hs-var">mkRnEnv2</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680964371"><span class="hs-identifier hs-var">in_scope</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964368"><span class="hs-identifier hs-var">tmpl_vars</span></a></span><span>
</span><span id="line-551"></span><span>                  </span><span class="hs-comment">-- See Note [Cloning the template binders]</span><span>
</span><span id="line-552"></span><span>
</span><span id="line-553"></span><span>    </span><span id="local-6989586621680964362"><span class="annot"><span class="annottext">init_menv :: RuleMatchEnv
</span><a href="#local-6989586621680964362"><span class="hs-identifier hs-var hs-var">init_menv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RV :: RnEnv2 -&gt; VarSet -&gt; Subst -&gt; (Var -&gt; Unfolding) -&gt; RuleMatchEnv
</span><a href="GHC.Core.Rules.html#RV"><span class="hs-identifier hs-type">RV</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rv_tmpls :: VarSet
</span><a href="GHC.Core.Rules.html#rv_tmpls"><span class="hs-identifier hs-var">rv_tmpls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964355"><span class="hs-identifier hs-var">tmpl_vars1</span></a></span><span>
</span><span id="line-554"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_lcl :: RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var">rv_lcl</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964349"><span class="hs-identifier hs-var">init_rn_env</span></a></span><span>
</span><span id="line-555"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_fltR :: Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var">rv_fltR</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Subst
</span><a href="GHC.Core.Subst.html#mkEmptySubst"><span class="hs-identifier hs-var">mkEmptySubst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RnEnv2 -&gt; InScopeSet
</span><a href="GHC.Types.Var.Env.html#rnInScopeSet"><span class="hs-identifier hs-var">rnInScopeSet</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964349"><span class="hs-identifier hs-var">init_rn_env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-556"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_unf :: Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rv_unf"><span class="hs-identifier hs-var">rv_unf</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Unfolding
</span><a href="#local-6989586621680964370"><span class="hs-identifier hs-var">id_unf</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-557"></span><span>
</span><span id="line-558"></span><span>    </span><span id="local-6989586621680964363"><span class="annot"><span class="annottext">go :: RuleMatchEnv
-&gt; RuleSubst -&gt; [CoreExpr] -&gt; [CoreExpr] -&gt; Maybe RuleSubst
</span><a href="#local-6989586621680964363"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span>    </span><span id="local-6989586621680964338"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964338"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span class="annot"><span class="annottext">[CoreExpr]
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964338"><span class="hs-identifier hs-var">subst</span></a></span><span>
</span><span id="line-559"></span><span>    </span><span class="annot"><a href="#local-6989586621680964363"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span>    </span><span class="annot"><span class="annottext">RuleSubst
</span><span class="hs-identifier">_</span></span><span>     </span><span class="annot"><span class="annottext">[CoreExpr]
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>       </span><span class="hs-comment">-- Fail if too few actual args</span><span>
</span><span id="line-560"></span><span>    </span><span class="annot"><a href="#local-6989586621680964363"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680964337"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964337"><span class="hs-identifier hs-var">menv</span></a></span></span><span> </span><span id="local-6989586621680964336"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964336"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964335"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964335"><span class="hs-identifier hs-var">t</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964334"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964334"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964333"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964333"><span class="hs-identifier hs-var">e</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964332"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964332"><span class="hs-identifier hs-var">es</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964331"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964331"><span class="hs-identifier hs-var">subst1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964337"><span class="hs-identifier hs-var">menv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964336"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964335"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964333"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-561"></span><span>                                     </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; [CoreExpr] -&gt; [CoreExpr] -&gt; Maybe RuleSubst
</span><a href="#local-6989586621680964363"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964337"><span class="hs-identifier hs-var">menv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964331"><span class="hs-identifier hs-var">subst1</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964334"><span class="hs-identifier hs-var">ts</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964332"><span class="hs-identifier hs-var">es</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-562"></span><span>
</span><span id="line-563"></span><span>    </span><span class="annot"><a href="#local-6989586621680964356"><span class="hs-identifier hs-type">lookup_tmpl</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#TCvSubst"><span class="hs-identifier hs-type">TCvSubst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#InVar"><span class="hs-identifier hs-type">InVar</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Types.Var.html#OutVar"><span class="hs-identifier hs-type">OutVar</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#TCvSubst"><span class="hs-identifier hs-type">TCvSubst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-564"></span><span>                   </span><span class="hs-comment">-- Need to return a RuleSubst solely for the benefit of mk_fake_ty</span><span>
</span><span id="line-565"></span><span>    </span><span id="local-6989586621680964356"><span class="annot"><span class="annottext">lookup_tmpl :: RuleSubst -&gt; TCvSubst -&gt; (Var, Var) -&gt; (TCvSubst, CoreExpr)
</span><a href="#local-6989586621680964356"><span class="hs-identifier hs-var hs-var">lookup_tmpl</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Rules.html#RS"><span class="hs-identifier hs-type">RS</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rs_tv_subst :: RuleSubst -&gt; TvSubstEnv
</span><a href="GHC.Core.Rules.html#rs_tv_subst"><span class="hs-identifier hs-var">rs_tv_subst</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964325"><span class="annot"><span class="annottext">TvSubstEnv
</span><a href="#local-6989586621680964325"><span class="hs-identifier hs-var">tv_subst</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rs_id_subst :: RuleSubst -&gt; IdSubstEnv
</span><a href="GHC.Core.Rules.html#rs_id_subst"><span class="hs-identifier hs-var">rs_id_subst</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964323"><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680964323"><span class="hs-identifier hs-var">id_subst</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-566"></span><span>                </span><span id="local-6989586621680964322"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680964322"><span class="hs-identifier hs-var">tcv_subst</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964321"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964321"><span class="hs-identifier hs-var">tmpl_var</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964320"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-567"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span><span>
</span><span id="line-568"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv -&gt; Var -&gt; Maybe CoreExpr
forall a. VarEnv a -&gt; Var -&gt; Maybe a
</span><a href="GHC.Types.Var.Env.html#lookupVarEnv"><span class="hs-identifier hs-var">lookupVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680964323"><span class="hs-identifier hs-var">id_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-569"></span><span>            </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964317"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964317"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span id="local-6989586621680964316"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964316"><span class="hs-identifier hs-var">co</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964317"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-570"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; Var -&gt; Coercion -&gt; TCvSubst
</span><a href="GHC.Core.TyCo.Subst.html#extendCvSubst"><span class="hs-identifier hs-var">Type.extendCvSubst</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680964322"><span class="hs-identifier hs-var">tcv_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964316"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; CoreExpr
forall b. Coercion -&gt; Expr b
</span><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-var">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964316"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-571"></span><span>                   </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-572"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680964322"><span class="hs-identifier hs-var">tcv_subst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964317"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-573"></span><span>            </span><span class="annot"><span class="annottext">Maybe CoreExpr
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964315"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964315"><span class="hs-identifier hs-var">refl_co</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Maybe Coercion
</span><a href="GHC.Core.Coercion.html#isReflCoVar_maybe"><span class="hs-identifier hs-var">isReflCoVar_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span><span>
</span><span id="line-574"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680964311"><span class="annot"><span class="annottext">co :: Coercion
</span><a href="#local-6989586621680964311"><span class="hs-identifier hs-var hs-var">co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; Coercion -&gt; Coercion
TCvSubst -&gt; Coercion -&gt; Coercion
</span><a href="GHC.Core.TyCo.Subst.html#substCo"><span class="hs-identifier hs-var">Coercion.substCo</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680964322"><span class="hs-identifier hs-var">tcv_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964315"><span class="hs-identifier hs-var">refl_co</span></a></span><span>
</span><span id="line-575"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-comment">-- See Note [Unbound RULE binders]</span><span>
</span><span id="line-576"></span><span>                       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; Var -&gt; Coercion -&gt; TCvSubst
</span><a href="GHC.Core.TyCo.Subst.html#extendCvSubst"><span class="hs-identifier hs-var">Type.extendCvSubst</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680964322"><span class="hs-identifier hs-var">tcv_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964311"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; CoreExpr
forall b. Coercion -&gt; Expr b
</span><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-var">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964311"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-577"></span><span>                    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-578"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Var -&gt; (TCvSubst, CoreExpr)
forall {a}. Var -&gt; a
</span><a href="#local-6989586621680964309"><span class="hs-identifier hs-var">unbound</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964321"><span class="hs-identifier hs-var">tmpl_var</span></a></span><span>
</span><span id="line-579"></span><span>
</span><span id="line-580"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-581"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; Var -&gt; Type -&gt; TCvSubst
</span><a href="GHC.Core.TyCo.Subst.html#extendTvSubst"><span class="hs-identifier hs-var">Type.extendTvSubst</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680964322"><span class="hs-identifier hs-var">tcv_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964308"><span class="hs-identifier hs-var">ty'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Type -&gt; CoreExpr
forall b. Type -&gt; Expr b
</span><a href="GHC.Core.html#Type"><span class="hs-identifier hs-var">Type</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964308"><span class="hs-identifier hs-var">ty'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-582"></span><span>        </span><span class="hs-keyword">where</span><span>
</span><span id="line-583"></span><span>          </span><span id="local-6989586621680964308"><span class="annot"><span class="annottext">ty' :: Type
</span><a href="#local-6989586621680964308"><span class="hs-identifier hs-var hs-var">ty'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TvSubstEnv -&gt; Var -&gt; Maybe Type
forall a. VarEnv a -&gt; Var -&gt; Maybe a
</span><a href="GHC.Types.Var.Env.html#lookupVarEnv"><span class="hs-identifier hs-var">lookupVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">TvSubstEnv
</span><a href="#local-6989586621680964325"><span class="hs-identifier hs-var">tv_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-584"></span><span>                  </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964307"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964307"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964307"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-585"></span><span>                  </span><span class="annot"><span class="annottext">Maybe Type
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964306"><span class="hs-identifier hs-var">fake_ty</span></a></span><span>   </span><span class="hs-comment">-- See Note [Unbound RULE binders]</span><span>
</span><span id="line-586"></span><span>          </span><span id="local-6989586621680964306"><span class="annot"><span class="annottext">fake_ty :: Type
</span><a href="#local-6989586621680964306"><span class="hs-identifier hs-var hs-var">fake_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type
</span><a href="GHC.Builtin.Types.html#anyTypeOfKind"><span class="hs-identifier hs-var">anyTypeOfKind</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; Type -&gt; Type
TCvSubst -&gt; Type -&gt; Type
</span><a href="GHC.Core.TyCo.Subst.html#substTy"><span class="hs-identifier hs-var">Type.substTy</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680964322"><span class="hs-identifier hs-var">tcv_subst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Type
</span><a href="GHC.Types.Var.html#tyVarKind"><span class="hs-identifier hs-var">tyVarKind</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964320"><span class="hs-identifier hs-var">tmpl_var1</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-587"></span><span>                    </span><span class="hs-comment">-- This substitution is the sole reason we accumulate</span><span>
</span><span id="line-588"></span><span>                    </span><span class="hs-comment">-- TCvSubst in lookup_tmpl</span><span>
</span><span id="line-589"></span><span>
</span><span id="line-590"></span><span>    </span><span id="local-6989586621680964309"><span class="annot"><span class="annottext">unbound :: Var -&gt; a
</span><a href="#local-6989586621680964309"><span class="hs-identifier hs-var hs-var">unbound</span></a></span></span><span> </span><span id="local-6989586621680964292"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964292"><span class="hs-identifier hs-var">tmpl_var</span></a></span></span><span>
</span><span id="line-591"></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; a
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Template variable unbound in rewrite rule&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; a) -&gt; SDoc -&gt; a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-592"></span><span>         </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Variable:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964292"><span class="hs-identifier hs-var">tmpl_var</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#dcolon"><span class="hs-identifier hs-var">dcolon</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Type
</span><a href="GHC.Types.Var.html#varType"><span class="hs-identifier hs-var hs-var">varType</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964292"><span class="hs-identifier hs-var">tmpl_var</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-593"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Rule&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName -&gt; SDoc
</span><a href="GHC.Types.Basic.html#pprRuleName"><span class="hs-identifier hs-var">pprRuleName</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680964369"><span class="hs-identifier hs-var">rule_name</span></a></span><span>
</span><span id="line-594"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Rule bndrs:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964368"><span class="hs-identifier hs-var">tmpl_vars</span></a></span><span>
</span><span id="line-595"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;LHS args:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964367"><span class="hs-identifier hs-var">tmpl_es</span></a></span><span>
</span><span id="line-596"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Actual args:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964366"><span class="hs-identifier hs-var">target_es</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-597"></span><span>
</span><span id="line-598"></span><span>
</span><span id="line-599"></span><span class="hs-comment">{- Note [Unbound RULE binders]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It can be the case that the binder in a rule is not actually
bound on the LHS:

* Type variables.  Type synonyms with phantom args can give rise to
  unbound template type variables.  Consider this (#10689,
  simplCore/should_compile/T10689):

    type Foo a b = b

    f :: Eq a =&gt; a -&gt; Bool
    f x = x==x

    {-# RULES &quot;foo&quot; forall (x :: Foo a Char). f x = True #-}
    finkle = f 'c'

  The rule looks like
    forall (a::*) (d::Eq Char) (x :: Foo a Char).
         f (Foo a Char) d x = True

  Matching the rule won't bind 'a', and legitimately so.  We fudge by
  pretending that 'a' is bound to (Any :: *).

* Coercion variables.  On the LHS of a RULE for a local binder
  we might have
    RULE forall (c :: a~b). f (x |&gt; c) = e
  Now, if that binding is inlined, so that a=b=Int, we'd get
    RULE forall (c :: Int~Int). f (x |&gt; c) = e
  and now when we simplify the LHS (Simplify.simplRule) we
  optCoercion (look at the CoVarCo case) will turn that 'c' into Refl:
    RULE forall (c :: Int~Int). f (x |&gt; &lt;Int&gt;) = e
  and then perhaps drop it altogether.  Now 'c' is unbound.

  It's tricky to be sure this never happens, so instead I
  say it's OK to have an unbound coercion binder in a RULE
  provided its type is (c :: t~t).  Then, when the RULE
  fires we can substitute &lt;t&gt; for c.

  This actually happened (in a RULE for a local function)
  in #13410, and also in test T10602.

Note [Cloning the template binders]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider the following match (example 1):
        Template:  forall x.  f x
        Target:               f (x+1)
This should succeed, because the template variable 'x' has nothing to
do with the 'x' in the target.

Likewise this one (example 2):
        Template:  forall x. f (\x.x)
        Target:              f (\y.y)

We achieve this simply by using rnBndrL to clone the template
binders if they are already in scope.

------ Historical note -------
At one point I tried simply adding the template binders to the
in-scope set /without/ cloning them, but that failed in a horribly
obscure way in #14777.  Problem was that during matching we look
up target-term variables in the in-scope set (see Note [Lookup
in-scope]).  If a target-term variable happens to name-clash with a
template variable, that lookup will find the template variable, which
is /utterly/ bogus.  In #14777, this transformed a term variable
into a type variable, and then crashed when we wanted its idInfo.
------ End of historical note -------


************************************************************************
*                                                                      *
                   The main matcher
*                                                                      *
********************************************************************* -}</span><span>
</span><span id="line-673"></span><span>
</span><span id="line-674"></span><span class="hs-comment">-- * The domain of the TvSubstEnv and IdSubstEnv are the template</span><span>
</span><span id="line-675"></span><span class="hs-comment">--   variables passed into the match.</span><span>
</span><span id="line-676"></span><span class="hs-comment">--</span><span>
</span><span id="line-677"></span><span class="hs-comment">-- * The BindWrapper in a RuleSubst are the bindings floated out</span><span>
</span><span id="line-678"></span><span class="hs-comment">--   from nested matches; see the Let case of match, below</span><span>
</span><span id="line-679"></span><span class="hs-comment">--</span><span>
</span><span id="line-680"></span><span class="hs-keyword">data</span><span> </span><span id="RuleMatchEnv"><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-var">RuleMatchEnv</span></a></span></span><span>
</span><span id="line-681"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="RV"><span class="annot"><a href="GHC.Core.Rules.html#RV"><span class="hs-identifier hs-var">RV</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="rv_lcl"><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var hs-var">rv_lcl</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html#RnEnv2"><span class="hs-identifier hs-type">RnEnv2</span></a></span><span>          </span><span class="hs-comment">-- Renamings for *local bindings*</span><span>
</span><span id="line-682"></span><span>                                     </span><span class="hs-comment">--   (lambda/case)</span><span>
</span><span id="line-683"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="rv_tmpls"><span class="annot"><span class="annottext">RuleMatchEnv -&gt; VarSet
</span><a href="GHC.Core.Rules.html#rv_tmpls"><span class="hs-identifier hs-var hs-var">rv_tmpls</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html#VarSet"><span class="hs-identifier hs-type">VarSet</span></a></span><span>          </span><span class="hs-comment">-- Template variables</span><span>
</span><span id="line-684"></span><span>                                     </span><span class="hs-comment">--   (after applying envL of rv_lcl)</span><span>
</span><span id="line-685"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="rv_fltR"><span class="annot"><span class="annottext">RuleMatchEnv -&gt; Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var hs-var">rv_fltR</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span>           </span><span class="hs-comment">-- Renamings for floated let-bindings</span><span>
</span><span id="line-686"></span><span>                                     </span><span class="hs-comment">--   (domain disjoint from envR of rv_lcl)</span><span>
</span><span id="line-687"></span><span>                                     </span><span class="hs-comment">-- See Note [Matching lets]</span><span>
</span><span id="line-688"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="rv_unf"><span class="annot"><span class="annottext">RuleMatchEnv -&gt; Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rv_unf"><span class="hs-identifier hs-var hs-var">rv_unf</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#IdUnfoldingFun"><span class="hs-identifier hs-type">IdUnfoldingFun</span></a></span><span>
</span><span id="line-689"></span><span>       </span><span class="hs-special">}</span><span>
</span><span id="line-690"></span><span>
</span><span id="line-691"></span><span class="annot"><a href="GHC.Core.Rules.html#rvInScopeEnv"><span class="hs-identifier hs-type">rvInScopeEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#InScopeEnv"><span class="hs-identifier hs-type">InScopeEnv</span></a></span><span>
</span><span id="line-692"></span><span id="rvInScopeEnv"><span class="annot"><span class="annottext">rvInScopeEnv :: RuleMatchEnv -&gt; InScopeEnv
</span><a href="GHC.Core.Rules.html#rvInScopeEnv"><span class="hs-identifier hs-var hs-var">rvInScopeEnv</span></a></span></span><span> </span><span id="local-6989586621680964285"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964285"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RnEnv2 -&gt; InScopeSet
</span><a href="GHC.Types.Var.Env.html#rnInScopeSet"><span class="hs-identifier hs-var">rnInScopeSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var hs-var">rv_lcl</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964285"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rv_unf"><span class="hs-identifier hs-var hs-var">rv_unf</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964285"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-693"></span><span>
</span><span id="line-694"></span><span class="hs-keyword">data</span><span> </span><span id="RuleSubst"><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-var">RuleSubst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="RS"><span class="annot"><a href="GHC.Core.Rules.html#RS"><span class="hs-identifier hs-var">RS</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="rs_tv_subst"><span class="annot"><span class="annottext">RuleSubst -&gt; TvSubstEnv
</span><a href="GHC.Core.Rules.html#rs_tv_subst"><span class="hs-identifier hs-var hs-var">rs_tv_subst</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#TvSubstEnv"><span class="hs-identifier hs-type">TvSubstEnv</span></a></span><span>   </span><span class="hs-comment">-- Range is the</span><span>
</span><span id="line-695"></span><span>                    </span><span class="hs-special">,</span><span> </span><span id="rs_id_subst"><span class="annot"><span class="annottext">RuleSubst -&gt; IdSubstEnv
</span><a href="GHC.Core.Rules.html#rs_id_subst"><span class="hs-identifier hs-var hs-var">rs_id_subst</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Subst.html#IdSubstEnv"><span class="hs-identifier hs-type">IdSubstEnv</span></a></span><span>   </span><span class="hs-comment">--   template variables</span><span>
</span><span id="line-696"></span><span>                    </span><span class="hs-special">,</span><span> </span><span id="rs_binds"><span class="annot"><span class="annottext">RuleSubst -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var hs-var">rs_binds</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#BindWrapper"><span class="hs-identifier hs-type">BindWrapper</span></a></span><span>  </span><span class="hs-comment">-- Floated bindings</span><span>
</span><span id="line-697"></span><span>                    </span><span class="hs-special">,</span><span> </span><span id="rs_bndrs"><span class="annot"><span class="annottext">RuleSubst -&gt; VarSet
</span><a href="GHC.Core.Rules.html#rs_bndrs"><span class="hs-identifier hs-var hs-var">rs_bndrs</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html#VarSet"><span class="hs-identifier hs-type">VarSet</span></a></span><span>       </span><span class="hs-comment">-- Variables bound by floated lets</span><span>
</span><span id="line-698"></span><span>                    </span><span class="hs-special">}</span><span>
</span><span id="line-699"></span><span>
</span><span id="line-700"></span><span class="hs-keyword">type</span><span> </span><span id="BindWrapper"><span class="annot"><a href="GHC.Core.Rules.html#BindWrapper"><span class="hs-identifier hs-var">BindWrapper</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-701"></span><span>  </span><span class="hs-comment">-- See Notes [Matching lets] and [Matching cases]</span><span>
</span><span id="line-702"></span><span>  </span><span class="hs-comment">-- we represent the floated bindings as a core-to-core function</span><span>
</span><span id="line-703"></span><span>
</span><span id="line-704"></span><span class="annot"><a href="GHC.Core.Rules.html#emptyRuleSubst"><span class="hs-identifier hs-type">emptyRuleSubst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-705"></span><span id="emptyRuleSubst"><span class="annot"><span class="annottext">emptyRuleSubst :: RuleSubst
</span><a href="GHC.Core.Rules.html#emptyRuleSubst"><span class="hs-identifier hs-var hs-var">emptyRuleSubst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RS :: TvSubstEnv
-&gt; IdSubstEnv -&gt; (CoreExpr -&gt; CoreExpr) -&gt; VarSet -&gt; RuleSubst
</span><a href="GHC.Core.Rules.html#RS"><span class="hs-identifier hs-type">RS</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rs_tv_subst :: TvSubstEnv
</span><a href="GHC.Core.Rules.html#rs_tv_subst"><span class="hs-identifier hs-var">rs_tv_subst</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TvSubstEnv
forall a. VarEnv a
</span><a href="GHC.Types.Var.Env.html#emptyVarEnv"><span class="hs-identifier hs-var">emptyVarEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rs_id_subst :: IdSubstEnv
</span><a href="GHC.Core.Rules.html#rs_id_subst"><span class="hs-identifier hs-var">rs_id_subst</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
forall a. VarEnv a
</span><a href="GHC.Types.Var.Env.html#emptyVarEnv"><span class="hs-identifier hs-var">emptyVarEnv</span></a></span><span>
</span><span id="line-706"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rs_binds :: CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var">rs_binds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621680964281"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964281"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964281"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rs_bndrs :: VarSet
</span><a href="GHC.Core.Rules.html#rs_bndrs"><span class="hs-identifier hs-var">rs_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="GHC.Types.Var.Set.html#emptyVarSet"><span class="hs-identifier hs-var">emptyVarSet</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-707"></span><span>
</span><span id="line-708"></span><span class="hs-comment">--      At one stage I tried to match even if there are more</span><span>
</span><span id="line-709"></span><span class="hs-comment">--      template args than real args.</span><span>
</span><span id="line-710"></span><span>
</span><span id="line-711"></span><span class="hs-comment">--      I now think this is probably a bad idea.</span><span>
</span><span id="line-712"></span><span class="hs-comment">--      Should the template (map f xs) match (map g)?  I think not.</span><span>
</span><span id="line-713"></span><span class="hs-comment">--      For a start, in general eta expansion wastes work.</span><span>
</span><span id="line-714"></span><span class="hs-comment">--      SLPJ July 99</span><span>
</span><span id="line-715"></span><span>
</span><span id="line-716"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-type">match</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span>
</span><span id="line-717"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-718"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>               </span><span class="hs-comment">-- Template</span><span>
</span><span id="line-719"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>               </span><span class="hs-comment">-- Target</span><span>
</span><span id="line-720"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-721"></span><span>
</span><span id="line-722"></span><span class="hs-comment">-- We look through certain ticks. See Note [Tick annotations in RULE matching]</span><span>
</span><span id="line-723"></span><span id="match"><span class="annot"><span class="annottext">match :: RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var hs-var">match</span></a></span></span><span> </span><span id="local-6989586621680964279"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964279"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964278"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964278"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964277"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964277"><span class="hs-identifier hs-var">e1</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680964276"><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680964276"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680964275"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964275"><span class="hs-identifier hs-var">e2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-724"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680964276"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-725"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964279"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964274"><span class="hs-identifier hs-var">subst'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964277"><span class="hs-identifier hs-var">e1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964275"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-726"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621680964274"><span class="annot"><span class="annottext">subst' :: RuleSubst
</span><a href="#local-6989586621680964274"><span class="hs-identifier hs-var hs-var">subst'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964278"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rs_binds :: CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var">rs_binds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var hs-var">rs_binds</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964278"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; CoreExpr)
-&gt; (CoreExpr -&gt; CoreExpr) -&gt; CoreExpr -&gt; CoreExpr
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Utils.html#mkTick"><span class="hs-identifier hs-var">mkTick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680964276"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-727"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964273"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964273"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964272"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964272"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680964271"><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680964271"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680964270"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964270"><span class="hs-identifier hs-var">e1</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680964269"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964269"><span class="hs-identifier hs-var">e2</span></a></span></span><span>
</span><span id="line-728"></span><span>  </span><span class="hs-comment">-- Ignore ticks in rule template.</span><span>
</span><span id="line-729"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680964271"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-730"></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964273"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964272"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964270"><span class="hs-identifier hs-var">e1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964269"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-731"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964268"><span class="annot"><span class="annottext">e :: CoreExpr
</span><a href="#local-6989586621680964268"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span class="hs-special">{</span><span class="hs-special">}</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><span class="hs-identifier">_</span></span><span>
</span><span id="line-732"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; Maybe RuleSubst
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Tick in rule&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964268"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-733"></span><span>
</span><span id="line-734"></span><span class="hs-comment">-- See the notes with Unify.match, which matches types</span><span>
</span><span id="line-735"></span><span class="hs-comment">-- Everything is very similar for terms</span><span>
</span><span id="line-736"></span><span>
</span><span id="line-737"></span><span class="hs-comment">-- Interesting examples:</span><span>
</span><span id="line-738"></span><span class="hs-comment">-- Consider matching</span><span>
</span><span id="line-739"></span><span class="hs-comment">--      \x-&gt;f      against    \f-&gt;f</span><span>
</span><span id="line-740"></span><span class="hs-comment">-- When we meet the lambdas we must remember to rename f to f' in the</span><span>
</span><span id="line-741"></span><span class="hs-comment">-- second expression.  The RnEnv2 does that.</span><span>
</span><span id="line-742"></span><span class="hs-comment">--</span><span>
</span><span id="line-743"></span><span class="hs-comment">-- Consider matching</span><span>
</span><span id="line-744"></span><span class="hs-comment">--      forall a. \b-&gt;b    against   \a-&gt;3</span><span>
</span><span id="line-745"></span><span class="hs-comment">-- We must rename the \a.  Otherwise when we meet the lambdas we</span><span>
</span><span id="line-746"></span><span class="hs-comment">-- might substitute [a/b] in the template, and then erroneously</span><span>
</span><span id="line-747"></span><span class="hs-comment">-- succeed in matching what looks like the template variable 'a' against 3.</span><span>
</span><span id="line-748"></span><span>
</span><span id="line-749"></span><span class="hs-comment">-- The Var case follows closely what happens in GHC.Core.Unify.match</span><span>
</span><span id="line-750"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964267"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964267"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964266"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964266"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680964265"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964265"><span class="hs-identifier hs-var">v1</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680964264"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964264"><span class="hs-identifier hs-var">e2</span></a></span></span><span>
</span><span id="line-751"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Var -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_var"><span class="hs-identifier hs-var">match_var</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964267"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964266"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964265"><span class="hs-identifier hs-var">v1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964264"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-752"></span><span>
</span><span id="line-753"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964262"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964262"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964261"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964261"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964260"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964260"><span class="hs-identifier hs-var">e1</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680964259"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964259"><span class="hs-identifier hs-var">v2</span></a></span></span><span class="hs-special">)</span><span>      </span><span class="hs-comment">-- Note [Expanding variables]</span><span>
</span><span id="line-754"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; Bool
</span><a href="GHC.Types.Var.Env.html#inRnEnvR"><span class="hs-identifier hs-var">inRnEnvR</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964257"><span class="hs-identifier hs-var">rn_env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964259"><span class="hs-identifier hs-var">v2</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- Note [Do not expand locally-bound variables]</span><span>
</span><span id="line-755"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964256"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964256"><span class="hs-identifier hs-var">e2'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Maybe CoreExpr
</span><a href="GHC.Core.html#expandUnfolding_maybe"><span class="hs-identifier hs-var">expandUnfolding_maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rv_unf"><span class="hs-identifier hs-var hs-var">rv_unf</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964262"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964254"><span class="hs-identifier hs-var">v2'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-756"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964262"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rv_lcl :: RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var">rv_lcl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; RnEnv2
</span><a href="GHC.Types.Var.Env.html#nukeRnEnvR"><span class="hs-identifier hs-var">nukeRnEnvR</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964257"><span class="hs-identifier hs-var">rn_env</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964261"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964260"><span class="hs-identifier hs-var">e1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964256"><span class="hs-identifier hs-var">e2'</span></a></span><span>
</span><span id="line-757"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-758"></span><span>    </span><span id="local-6989586621680964254"><span class="annot"><span class="annottext">v2' :: Var
</span><a href="#local-6989586621680964254"><span class="hs-identifier hs-var hs-var">v2'</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; Var
</span><a href="GHC.Types.Var.Env.html#lookupRnInScope"><span class="hs-identifier hs-var">lookupRnInScope</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964257"><span class="hs-identifier hs-var">rn_env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964259"><span class="hs-identifier hs-var">v2</span></a></span><span>
</span><span id="line-759"></span><span>    </span><span id="local-6989586621680964257"><span class="annot"><span class="annottext">rn_env :: RnEnv2
</span><a href="#local-6989586621680964257"><span class="hs-identifier hs-var hs-var">rn_env</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var hs-var">rv_lcl</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964262"><span class="hs-identifier hs-var">renv</span></a></span><span>
</span><span id="line-760"></span><span>        </span><span class="hs-comment">-- Notice that we look up v2 in the in-scope set</span><span>
</span><span id="line-761"></span><span>        </span><span class="hs-comment">-- See Note [Lookup in-scope]</span><span>
</span><span id="line-762"></span><span>        </span><span class="hs-comment">-- No need to apply any renaming first (hence no rnOccR)</span><span>
</span><span id="line-763"></span><span>        </span><span class="hs-comment">-- because of the not-inRnEnvR</span><span>
</span><span id="line-764"></span><span>
</span><span id="line-765"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964251"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964251"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964250"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964250"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964249"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964249"><span class="hs-identifier hs-var">e1</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span id="local-6989586621680964247"><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964247"><span class="hs-identifier hs-var">bind</span></a></span></span><span> </span><span id="local-6989586621680964246"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964246"><span class="hs-identifier hs-var">e2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-766"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-comment">-- pprTrace &quot;match:Let&quot; (vcat [ppr bind, ppr $ okToFloat (rv_lcl renv) (bindFreeVars bind)]) $</span><span>
</span><span id="line-767"></span><span>    </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreBind -&gt; Bool
</span><a href="GHC.Core.Utils.html#isJoinBind"><span class="hs-identifier hs-var">isJoinBind</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964247"><span class="hs-identifier hs-var">bind</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- can't float join point out of argument position</span><span>
</span><span id="line-768"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; VarSet -&gt; Bool
</span><a href="GHC.Core.Rules.html#okToFloat"><span class="hs-identifier hs-var">okToFloat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var hs-var">rv_lcl</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964251"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreBind -&gt; VarSet
</span><a href="GHC.Core.FVs.html#bindFreeVars"><span class="hs-identifier hs-var">bindFreeVars</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964247"><span class="hs-identifier hs-var">bind</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- See Note [Matching lets]</span><span>
</span><span id="line-769"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964251"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rv_fltR :: Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var">rv_fltR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680964244"><span class="hs-identifier hs-var">flt_subst'</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-770"></span><span>          </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964250"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rs_binds :: CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var">rs_binds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var hs-var">rs_binds</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964250"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; CoreExpr)
-&gt; (CoreExpr -&gt; CoreExpr) -&gt; CoreExpr -&gt; CoreExpr
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind -&gt; CoreExpr -&gt; CoreExpr
forall b. Bind b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Let"><span class="hs-identifier hs-var">Let</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964243"><span class="hs-identifier hs-var">bind'</span></a></span><span>
</span><span id="line-771"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rs_bndrs :: VarSet
</span><a href="GHC.Core.Rules.html#rs_bndrs"><span class="hs-identifier hs-var">rs_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; [Var] -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#extendVarSetList"><span class="hs-identifier hs-var">extendVarSetList</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleSubst -&gt; VarSet
</span><a href="GHC.Core.Rules.html#rs_bndrs"><span class="hs-identifier hs-var hs-var">rs_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964250"><span class="hs-identifier hs-var">subst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964241"><span class="hs-identifier hs-var">new_bndrs</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-772"></span><span>          </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964249"><span class="hs-identifier hs-var">e1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964246"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-773"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-774"></span><span>    </span><span id="local-6989586621680964240"><span class="annot"><span class="annottext">flt_subst :: Subst
</span><a href="#local-6989586621680964240"><span class="hs-identifier hs-var hs-var">flt_subst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Subst -&gt; VarSet -&gt; Subst
</span><a href="GHC.Core.Subst.html#addInScopeSet"><span class="hs-identifier hs-var">addInScopeSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var hs-var">rv_fltR</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964251"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleSubst -&gt; VarSet
</span><a href="GHC.Core.Rules.html#rs_bndrs"><span class="hs-identifier hs-var hs-var">rs_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964250"><span class="hs-identifier hs-var">subst</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-775"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680964244"><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680964244"><span class="hs-identifier hs-var">flt_subst'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964243"><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964243"><span class="hs-identifier hs-var">bind'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Subst -&gt; CoreBind -&gt; (Subst, CoreBind)
Subst -&gt; CoreBind -&gt; (Subst, CoreBind)
</span><a href="GHC.Core.Subst.html#substBind"><span class="hs-identifier hs-var">substBind</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680964240"><span class="hs-identifier hs-var">flt_subst</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964247"><span class="hs-identifier hs-var">bind</span></a></span><span>
</span><span id="line-776"></span><span>    </span><span id="local-6989586621680964241"><span class="annot"><span class="annottext">new_bndrs :: [Var]
</span><a href="#local-6989586621680964241"><span class="hs-identifier hs-var hs-var">new_bndrs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreBind -&gt; [Var]
forall b. Bind b -&gt; [b]
</span><a href="GHC.Core.html#bindersOf"><span class="hs-identifier hs-var">bindersOf</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964243"><span class="hs-identifier hs-var">bind'</span></a></span><span>
</span><span id="line-777"></span><span>
</span><span id="line-778"></span><span class="hs-comment">{- Disabled: see Note [Matching cases] below
match renv (tv_subst, id_subst, binds) e1
      (Case scrut case_bndr ty [(con, alt_bndrs, rhs)])
  | exprOkForSpeculation scrut  -- See Note [Matching cases]
  , okToFloat rn_env bndrs (exprFreeVars scrut)
  = match (renv { me_env = rn_env' })
          (tv_subst, id_subst, binds . case_wrap)
          e1 rhs
  where
    rn_env   = me_env renv
    rn_env'  = extendRnInScopeList rn_env bndrs
    bndrs    = case_bndr : alt_bndrs
    case_wrap rhs' = Case scrut case_bndr ty [(con, alt_bndrs, rhs')]
-}</span><span>
</span><span id="line-792"></span><span>
</span><span id="line-793"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964236"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964236"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span id="local-6989586621680964234"><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680964234"><span class="hs-identifier hs-var">lit1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span id="local-6989586621680964233"><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680964233"><span class="hs-identifier hs-var">lit2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-794"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680964234"><span class="hs-identifier hs-var">lit1</span></a></span><span> </span><span class="annot"><span class="annottext">Literal -&gt; Literal -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680964233"><span class="hs-identifier hs-var">lit2</span></a></span><span>
</span><span id="line-795"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964236"><span class="hs-identifier hs-var">subst</span></a></span><span>
</span><span id="line-796"></span><span>
</span><span id="line-797"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964232"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964232"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964231"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964231"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680964230"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964230"><span class="hs-identifier hs-var">f1</span></a></span></span><span> </span><span id="local-6989586621680964229"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964229"><span class="hs-identifier hs-var">a1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680964228"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964228"><span class="hs-identifier hs-var">f2</span></a></span></span><span> </span><span id="local-6989586621680964227"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964227"><span class="hs-identifier hs-var">a2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-798"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964226"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964226"><span class="hs-identifier hs-var">subst'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964232"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964231"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964230"><span class="hs-identifier hs-var">f1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964228"><span class="hs-identifier hs-var">f2</span></a></span><span>
</span><span id="line-799"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964232"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964226"><span class="hs-identifier hs-var">subst'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964229"><span class="hs-identifier hs-var">a1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964227"><span class="hs-identifier hs-var">a2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-800"></span><span>
</span><span id="line-801"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964225"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964225"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964224"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964224"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span id="local-6989586621680964222"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964222"><span class="hs-identifier hs-var">x1</span></a></span></span><span> </span><span id="local-6989586621680964221"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964221"><span class="hs-identifier hs-var">e1</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680964220"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964220"><span class="hs-identifier hs-var">e2</span></a></span></span><span>
</span><span id="line-802"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964219"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964219"><span class="hs-identifier hs-var">x2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964218"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964218"><span class="hs-identifier hs-var">e2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964217"><span class="annot"><span class="annottext">[Tickish Var]
</span><a href="#local-6989586621680964217"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">InScopeEnv -&gt; CoreExpr -&gt; Maybe (Var, CoreExpr, [Tickish Var])
</span><a href="GHC.Core.SimpleOpt.html#exprIsLambda_maybe"><span class="hs-identifier hs-var">exprIsLambda_maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; InScopeEnv
</span><a href="GHC.Core.Rules.html#rvInScopeEnv"><span class="hs-identifier hs-var">rvInScopeEnv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964225"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964220"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-803"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680964216"><span class="annot"><span class="annottext">renv' :: RuleMatchEnv
</span><a href="#local-6989586621680964216"><span class="hs-identifier hs-var hs-var">renv'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964225"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rv_lcl :: RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var">rv_lcl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; Var -&gt; RnEnv2
</span><a href="GHC.Types.Var.Env.html#rnBndr2"><span class="hs-identifier hs-var">rnBndr2</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var hs-var">rv_lcl</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964225"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964222"><span class="hs-identifier hs-var">x1</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964219"><span class="hs-identifier hs-var">x2</span></a></span><span>
</span><span id="line-804"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_fltR :: Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var">rv_fltR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Subst -&gt; Var -&gt; Subst
</span><a href="GHC.Core.Subst.html#delBndr"><span class="hs-identifier hs-var">delBndr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var hs-var">rv_fltR</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964225"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964219"><span class="hs-identifier hs-var">x2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-805"></span><span>        </span><span id="local-6989586621680964212"><span class="annot"><span class="annottext">subst' :: RuleSubst
</span><a href="#local-6989586621680964212"><span class="hs-identifier hs-var hs-var">subst'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964224"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rs_binds :: CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var">rs_binds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Rules.html#rs_binds"><span class="hs-identifier hs-var hs-var">rs_binds</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964224"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; CoreExpr)
-&gt; (CoreExpr -&gt; CoreExpr) -&gt; CoreExpr -&gt; CoreExpr
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; [Tickish Var] -&gt; CoreExpr)
-&gt; [Tickish Var] -&gt; CoreExpr -&gt; CoreExpr
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Tickish Var -&gt; CoreExpr -&gt; CoreExpr)
-&gt; CoreExpr -&gt; [Tickish Var] -&gt; CoreExpr
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Utils.html#mkTick"><span class="hs-identifier hs-var">mkTick</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Tickish Var]
</span><a href="#local-6989586621680964217"><span class="hs-identifier hs-var">ts</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-806"></span><span>    </span><span class="hs-keyword">in</span><span>  </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964216"><span class="hs-identifier hs-var">renv'</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964212"><span class="hs-identifier hs-var">subst'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964221"><span class="hs-identifier hs-var">e1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964218"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-807"></span><span>
</span><span id="line-808"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964209"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964209"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964208"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964208"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680964206"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964206"><span class="hs-identifier hs-var">e1</span></a></span></span><span> </span><span id="local-6989586621680964205"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964205"><span class="hs-identifier hs-var">x1</span></a></span></span><span> </span><span id="local-6989586621680964204"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964204"><span class="hs-identifier hs-var">ty1</span></a></span></span><span> </span><span id="local-6989586621680964203"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964203"><span class="hs-identifier hs-var">alts1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680964202"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964202"><span class="hs-identifier hs-var">e2</span></a></span></span><span> </span><span id="local-6989586621680964201"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964201"><span class="hs-identifier hs-var">x2</span></a></span></span><span> </span><span id="local-6989586621680964200"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964200"><span class="hs-identifier hs-var">ty2</span></a></span></span><span> </span><span id="local-6989586621680964199"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964199"><span class="hs-identifier hs-var">alts2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-809"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964198"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964198"><span class="hs-identifier hs-var">subst1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Type -&gt; Type -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_ty"><span class="hs-identifier hs-var">match_ty</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964209"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964208"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964204"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964200"><span class="hs-identifier hs-var">ty2</span></a></span><span>
</span><span id="line-810"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621680964196"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964196"><span class="hs-identifier hs-var">subst2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964209"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964198"><span class="hs-identifier hs-var">subst1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964206"><span class="hs-identifier hs-var">e1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964202"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-811"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680964195"><span class="annot"><span class="annottext">renv' :: RuleMatchEnv
</span><a href="#local-6989586621680964195"><span class="hs-identifier hs-var hs-var">renv'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Var -&gt; Var -&gt; RuleMatchEnv
</span><a href="GHC.Core.Rules.html#rnMatchBndr2"><span class="hs-identifier hs-var">rnMatchBndr2</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964209"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964208"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964205"><span class="hs-identifier hs-var">x1</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964201"><span class="hs-identifier hs-var">x2</span></a></span><span>
</span><span id="line-812"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; [Alt Var] -&gt; [Alt Var] -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_alts"><span class="hs-identifier hs-var">match_alts</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964195"><span class="hs-identifier hs-var">renv'</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964196"><span class="hs-identifier hs-var">subst2</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964203"><span class="hs-identifier hs-var">alts1</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964199"><span class="hs-identifier hs-var">alts2</span></a></span><span>   </span><span class="hs-comment">-- Alts are both sorted</span><span>
</span><span id="line-813"></span><span>        </span><span class="hs-special">}</span><span>
</span><span id="line-814"></span><span>
</span><span id="line-815"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964192"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964192"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964191"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964191"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span id="local-6989586621680964190"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964190"><span class="hs-identifier hs-var">ty1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span id="local-6989586621680964189"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964189"><span class="hs-identifier hs-var">ty2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-816"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Type -&gt; Type -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_ty"><span class="hs-identifier hs-var">match_ty</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964192"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964191"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964190"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964189"><span class="hs-identifier hs-var">ty2</span></a></span><span>
</span><span id="line-817"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964188"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964188"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964187"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964187"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span id="local-6989586621680964186"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964186"><span class="hs-identifier hs-var">co1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span id="local-6989586621680964185"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964185"><span class="hs-identifier hs-var">co2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-818"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; Coercion -&gt; Coercion -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_co"><span class="hs-identifier hs-var">match_co</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964188"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964187"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964186"><span class="hs-identifier hs-var">co1</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964185"><span class="hs-identifier hs-var">co2</span></a></span><span>
</span><span id="line-819"></span><span>
</span><span id="line-820"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span id="local-6989586621680964183"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964183"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964182"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964182"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680964180"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964180"><span class="hs-identifier hs-var">e1</span></a></span></span><span> </span><span id="local-6989586621680964179"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964179"><span class="hs-identifier hs-var">co1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680964178"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964178"><span class="hs-identifier hs-var">e2</span></a></span></span><span> </span><span id="local-6989586621680964177"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964177"><span class="hs-identifier hs-var">co2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-821"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964176"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964176"><span class="hs-identifier hs-var">subst1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; Coercion -&gt; Coercion -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_co"><span class="hs-identifier hs-var">match_co</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964183"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964182"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964179"><span class="hs-identifier hs-var">co1</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964177"><span class="hs-identifier hs-var">co2</span></a></span><span>
</span><span id="line-822"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964183"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964176"><span class="hs-identifier hs-var">subst1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964180"><span class="hs-identifier hs-var">e1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964178"><span class="hs-identifier hs-var">e2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-823"></span><span>
</span><span id="line-824"></span><span class="hs-comment">-- Everything else fails</span><span>
</span><span id="line-825"></span><span class="annot"><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964175"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964175"><span class="hs-identifier hs-var">_e1</span></a></span></span><span> </span><span id="local-6989586621680964174"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964174"><span class="hs-identifier hs-var">_e2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;Failing at&quot; ((text &quot;e1:&quot; &lt;+&gt; ppr _e1) $$ (text &quot;e2:&quot; &lt;+&gt; ppr _e2)) $</span><span>
</span><span id="line-826"></span><span>                    </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-827"></span><span>
</span><span id="line-828"></span><span class="hs-comment">-------------</span><span>
</span><span id="line-829"></span><span class="annot"><a href="GHC.Core.Rules.html#match_co"><span class="hs-identifier hs-type">match_co</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span>
</span><span id="line-830"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-831"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span>
</span><span id="line-832"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span>
</span><span id="line-833"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-834"></span><span id="match_co"><span class="annot"><span class="annottext">match_co :: RuleMatchEnv
-&gt; RuleSubst -&gt; Coercion -&gt; Coercion -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_co"><span class="hs-identifier hs-var hs-var">match_co</span></a></span></span><span> </span><span id="local-6989586621680964173"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964173"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964172"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964172"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964171"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964171"><span class="hs-identifier hs-var">co1</span></a></span></span><span> </span><span id="local-6989586621680964170"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964170"><span class="hs-identifier hs-var">co2</span></a></span></span><span>
</span><span id="line-835"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964169"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964169"><span class="hs-identifier hs-var">cv</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; Maybe Var
</span><a href="GHC.Core.Coercion.html#getCoVar_maybe"><span class="hs-identifier hs-var">getCoVar_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964171"><span class="hs-identifier hs-var">co1</span></a></span><span>
</span><span id="line-836"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Var -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_var"><span class="hs-identifier hs-var">match_var</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964173"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964172"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964169"><span class="hs-identifier hs-var">cv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Coercion -&gt; CoreExpr
forall b. Coercion -&gt; Expr b
</span><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-var">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964170"><span class="hs-identifier hs-var">co2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-837"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964167"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964167"><span class="hs-identifier hs-var">ty1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964166"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621680964166"><span class="hs-identifier hs-var">r1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; Maybe (Type, Role)
</span><a href="GHC.Core.Coercion.html#isReflCo_maybe"><span class="hs-identifier hs-var">isReflCo_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964171"><span class="hs-identifier hs-var">co1</span></a></span><span>
</span><span id="line-838"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964164"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964164"><span class="hs-identifier hs-var">ty2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964163"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621680964163"><span class="hs-identifier hs-var">r2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; Maybe (Type, Role)
</span><a href="GHC.Core.Coercion.html#isReflCo_maybe"><span class="hs-identifier hs-var">isReflCo_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964170"><span class="hs-identifier hs-var">co2</span></a></span><span>
</span><span id="line-839"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Maybe ()
forall (f :: * -&gt; *). Alternative f =&gt; Bool -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#guard"><span class="hs-identifier hs-var">guard</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621680964166"><span class="hs-identifier hs-var">r1</span></a></span><span> </span><span class="annot"><span class="annottext">Role -&gt; Role -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621680964163"><span class="hs-identifier hs-var">r2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-840"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Type -&gt; Type -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_ty"><span class="hs-identifier hs-var">match_ty</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964173"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964172"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964167"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964164"><span class="hs-identifier hs-var">ty2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-841"></span><span class="annot"><a href="GHC.Core.Rules.html#match_co"><span class="hs-identifier hs-var">match_co</span></a></span><span> </span><span id="local-6989586621680964162"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964162"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964161"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964161"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964160"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964160"><span class="hs-identifier hs-var">co1</span></a></span></span><span> </span><span id="local-6989586621680964159"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964159"><span class="hs-identifier hs-var">co2</span></a></span></span><span>
</span><span id="line-842"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964158"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680964158"><span class="hs-identifier hs-var">tc1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964157"><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964157"><span class="hs-identifier hs-var">cos1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; Maybe (TyCon, [Coercion])
</span><a href="GHC.Core.Coercion.html#splitTyConAppCo_maybe"><span class="hs-identifier hs-var">splitTyConAppCo_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964160"><span class="hs-identifier hs-var">co1</span></a></span><span>
</span><span id="line-843"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; Maybe (TyCon, [Coercion])
</span><a href="GHC.Core.Coercion.html#splitTyConAppCo_maybe"><span class="hs-identifier hs-var">splitTyConAppCo_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964159"><span class="hs-identifier hs-var">co2</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-844"></span><span>      </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964155"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680964155"><span class="hs-identifier hs-var">tc2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964154"><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964154"><span class="hs-identifier hs-var">cos2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-845"></span><span>        </span><span class="hs-glyph">|</span><span>  </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680964158"><span class="hs-identifier hs-var">tc1</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; TyCon -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680964155"><span class="hs-identifier hs-var">tc2</span></a></span><span>
</span><span id="line-846"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; [Coercion] -&gt; [Coercion] -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_cos"><span class="hs-identifier hs-var">match_cos</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964162"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964161"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964157"><span class="hs-identifier hs-var">cos1</span></a></span><span> </span><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964154"><span class="hs-identifier hs-var">cos2</span></a></span><span>
</span><span id="line-847"></span><span>      </span><span class="annot"><span class="annottext">Maybe (TyCon, [Coercion])
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-848"></span><span class="annot"><a href="GHC.Core.Rules.html#match_co"><span class="hs-identifier hs-var">match_co</span></a></span><span> </span><span id="local-6989586621680964152"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964152"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964151"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964151"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964150"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964150"><span class="hs-identifier hs-var">co1</span></a></span></span><span> </span><span id="local-6989586621680964149"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964149"><span class="hs-identifier hs-var">co2</span></a></span></span><span>
</span><span id="line-849"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964148"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964148"><span class="hs-identifier hs-var">arg1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964147"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964147"><span class="hs-identifier hs-var">res1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; Maybe (Coercion, Coercion)
</span><a href="GHC.Core.Coercion.html#splitFunCo_maybe"><span class="hs-identifier hs-var">splitFunCo_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964150"><span class="hs-identifier hs-var">co1</span></a></span><span>
</span><span id="line-850"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; Maybe (Coercion, Coercion)
</span><a href="GHC.Core.Coercion.html#splitFunCo_maybe"><span class="hs-identifier hs-var">splitFunCo_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964149"><span class="hs-identifier hs-var">co2</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-851"></span><span>      </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964145"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964145"><span class="hs-identifier hs-var">arg2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680964144"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964144"><span class="hs-identifier hs-var">res2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-852"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; [Coercion] -&gt; [Coercion] -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_cos"><span class="hs-identifier hs-var">match_cos</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964152"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964151"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964148"><span class="hs-identifier hs-var">arg1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964147"><span class="hs-identifier hs-var">res1</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964145"><span class="hs-identifier hs-var">arg2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964144"><span class="hs-identifier hs-var">res2</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-853"></span><span>      </span><span class="annot"><span class="annottext">Maybe (Coercion, Coercion)
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-854"></span><span class="annot"><a href="GHC.Core.Rules.html#match_co"><span class="hs-identifier hs-var">match_co</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964143"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964143"><span class="hs-identifier hs-var">_co1</span></a></span></span><span> </span><span id="local-6989586621680964142"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964142"><span class="hs-identifier hs-var">_co2</span></a></span></span><span>
</span><span id="line-855"></span><span>    </span><span class="hs-comment">-- Currently just deals with CoVarCo, TyConAppCo and Refl</span><span class="hs-cpp">
#if defined(DEBUG)
</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">pprTrace</span><span> </span><span class="hs-string">&quot;match_co: needs more cases&quot;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">_co1</span><span> </span><span class="hs-operator">$$</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">_co2</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-cpp">
#else
</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-862"></span><span class="annot"><a href="GHC.Core.Rules.html#match_cos"><span class="hs-identifier hs-type">match_cos</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span>
</span><span id="line-863"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-864"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-865"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-866"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-867"></span><span id="match_cos"><span class="annot"><span class="annottext">match_cos :: RuleMatchEnv
-&gt; RuleSubst -&gt; [Coercion] -&gt; [Coercion] -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_cos"><span class="hs-identifier hs-var hs-var">match_cos</span></a></span></span><span> </span><span id="local-6989586621680964141"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964141"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964140"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964140"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964139"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964139"><span class="hs-identifier hs-var">co1</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964138"><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964138"><span class="hs-identifier hs-var">cos1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964137"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964137"><span class="hs-identifier hs-var">co2</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964136"><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964136"><span class="hs-identifier hs-var">cos2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-868"></span><span>  </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964135"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964135"><span class="hs-identifier hs-var">subst'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; Coercion -&gt; Coercion -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_co"><span class="hs-identifier hs-var">match_co</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964141"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964140"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964139"><span class="hs-identifier hs-var">co1</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680964137"><span class="hs-identifier hs-var">co2</span></a></span><span>
</span><span id="line-869"></span><span>     </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; [Coercion] -&gt; [Coercion] -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_cos"><span class="hs-identifier hs-var">match_cos</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964141"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964135"><span class="hs-identifier hs-var">subst'</span></a></span><span> </span><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964138"><span class="hs-identifier hs-var">cos1</span></a></span><span> </span><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964136"><span class="hs-identifier hs-var">cos2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-870"></span><span class="annot"><a href="GHC.Core.Rules.html#match_cos"><span class="hs-identifier hs-var">match_cos</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964134"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964134"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964134"><span class="hs-identifier hs-var">subst</span></a></span><span>
</span><span id="line-871"></span><span class="annot"><a href="GHC.Core.Rules.html#match_cos"><span class="hs-identifier hs-var">match_cos</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964133"><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964133"><span class="hs-identifier hs-var">cos1</span></a></span></span><span> </span><span id="local-6989586621680964132"><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964132"><span class="hs-identifier hs-var">cos2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; Maybe RuleSubst -&gt; Maybe RuleSubst
forall a. String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprTrace"><span class="hs-identifier hs-var">pprTrace</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;match_cos: not same length&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Coercion] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964133"><span class="hs-identifier hs-var">cos1</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">[Coercion] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[Coercion]
</span><a href="#local-6989586621680964132"><span class="hs-identifier hs-var">cos2</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-872"></span><span>
</span><span id="line-873"></span><span class="hs-comment">-------------</span><span>
</span><span id="line-874"></span><span class="annot"><a href="GHC.Core.Rules.html#rnMatchBndr2"><span class="hs-identifier hs-type">rnMatchBndr2</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span>
</span><span id="line-875"></span><span id="rnMatchBndr2"><span class="annot"><span class="annottext">rnMatchBndr2 :: RuleMatchEnv -&gt; RuleSubst -&gt; Var -&gt; Var -&gt; RuleMatchEnv
</span><a href="GHC.Core.Rules.html#rnMatchBndr2"><span class="hs-identifier hs-var hs-var">rnMatchBndr2</span></a></span></span><span> </span><span id="local-6989586621680964130"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964130"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964129"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964129"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964128"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964128"><span class="hs-identifier hs-var">x1</span></a></span></span><span> </span><span id="local-6989586621680964127"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964127"><span class="hs-identifier hs-var">x2</span></a></span></span><span>
</span><span id="line-876"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964130"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rv_lcl :: RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var">rv_lcl</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; Var -&gt; RnEnv2
</span><a href="GHC.Types.Var.Env.html#rnBndr2"><span class="hs-identifier hs-var">rnBndr2</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964126"><span class="hs-identifier hs-var">rn_env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964128"><span class="hs-identifier hs-var">x1</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964127"><span class="hs-identifier hs-var">x2</span></a></span><span>
</span><span id="line-877"></span><span>         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_fltR :: Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var">rv_fltR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Subst -&gt; Var -&gt; Subst
</span><a href="GHC.Core.Subst.html#delBndr"><span class="hs-identifier hs-var">delBndr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var hs-var">rv_fltR</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964130"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964127"><span class="hs-identifier hs-var">x2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-878"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-879"></span><span>    </span><span id="local-6989586621680964126"><span class="annot"><span class="annottext">rn_env :: RnEnv2
</span><a href="#local-6989586621680964126"><span class="hs-identifier hs-var hs-var">rn_env</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; VarSet -&gt; RnEnv2
</span><a href="GHC.Types.Var.Env.html#addRnInScopeSet"><span class="hs-identifier hs-var">addRnInScopeSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var hs-var">rv_lcl</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964130"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleSubst -&gt; VarSet
</span><a href="GHC.Core.Rules.html#rs_bndrs"><span class="hs-identifier hs-var hs-var">rs_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964129"><span class="hs-identifier hs-var">subst</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-880"></span><span>    </span><span class="hs-comment">-- Typically this is a no-op, but it may matter if</span><span>
</span><span id="line-881"></span><span>    </span><span class="hs-comment">-- there are some floated let-bindings</span><span>
</span><span id="line-882"></span><span>
</span><span id="line-883"></span><span class="hs-comment">------------------------------------------</span><span>
</span><span id="line-884"></span><span class="annot"><a href="GHC.Core.Rules.html#match_alts"><span class="hs-identifier hs-type">match_alts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span>
</span><span id="line-885"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-886"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreAlt"><span class="hs-identifier hs-type">CoreAlt</span></a></span><span class="hs-special">]</span><span>         </span><span class="hs-comment">-- Template</span><span>
</span><span id="line-887"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreAlt"><span class="hs-identifier hs-type">CoreAlt</span></a></span><span class="hs-special">]</span><span>         </span><span class="hs-comment">-- Target</span><span>
</span><span id="line-888"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-889"></span><span id="match_alts"><span class="annot"><span class="annottext">match_alts :: RuleMatchEnv
-&gt; RuleSubst -&gt; [Alt Var] -&gt; [Alt Var] -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_alts"><span class="hs-identifier hs-var hs-var">match_alts</span></a></span></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964123"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964123"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-890"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964123"><span class="hs-identifier hs-var">subst</span></a></span><span>
</span><span id="line-891"></span><span class="annot"><a href="GHC.Core.Rules.html#match_alts"><span class="hs-identifier hs-var">match_alts</span></a></span><span> </span><span id="local-6989586621680964122"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964122"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964121"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964121"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621680964120"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680964120"><span class="hs-identifier hs-var">c1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964119"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964119"><span class="hs-identifier hs-var">vs1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964118"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964118"><span class="hs-identifier hs-var">r1</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964117"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964117"><span class="hs-identifier hs-var">alts1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621680964116"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680964116"><span class="hs-identifier hs-var">c2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964115"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964115"><span class="hs-identifier hs-var">vs2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964114"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964114"><span class="hs-identifier hs-var">r2</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680964113"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964113"><span class="hs-identifier hs-var">alts2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-892"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680964120"><span class="hs-identifier hs-var">c1</span></a></span><span> </span><span class="annot"><span class="annottext">AltCon -&gt; AltCon -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680964116"><span class="hs-identifier hs-var">c2</span></a></span><span>
</span><span id="line-893"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964112"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964112"><span class="hs-identifier hs-var">subst1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964111"><span class="hs-identifier hs-var">renv'</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964121"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964118"><span class="hs-identifier hs-var">r1</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964114"><span class="hs-identifier hs-var">r2</span></a></span><span>
</span><span id="line-894"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; [Alt Var] -&gt; [Alt Var] -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_alts"><span class="hs-identifier hs-var">match_alts</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964122"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964112"><span class="hs-identifier hs-var">subst1</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964117"><span class="hs-identifier hs-var">alts1</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964113"><span class="hs-identifier hs-var">alts2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-895"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-896"></span><span>    </span><span id="local-6989586621680964111"><span class="annot"><span class="annottext">renv' :: RuleMatchEnv
</span><a href="#local-6989586621680964111"><span class="hs-identifier hs-var hs-var">renv'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(RuleMatchEnv -&gt; (Var, Var) -&gt; RuleMatchEnv)
-&gt; RuleMatchEnv -&gt; [(Var, Var)] -&gt; RuleMatchEnv
forall (t :: * -&gt; *) b a.
Foldable t =&gt;
(b -&gt; a -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldl%27"><span class="hs-identifier hs-var">foldl'</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; (Var, Var) -&gt; RuleMatchEnv
</span><a href="#local-6989586621680964109"><span class="hs-identifier hs-var">mb</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964122"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964119"><span class="hs-identifier hs-var">vs1</span></a></span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; [Var] -&gt; [(Var, Var)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-operator hs-var">`zip`</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680964115"><span class="hs-identifier hs-var">vs2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-897"></span><span>    </span><span id="local-6989586621680964109"><span class="annot"><span class="annottext">mb :: RuleMatchEnv -&gt; (Var, Var) -&gt; RuleMatchEnv
</span><a href="#local-6989586621680964109"><span class="hs-identifier hs-var hs-var">mb</span></a></span></span><span> </span><span id="local-6989586621680964108"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964108"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680964107"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964107"><span class="hs-identifier hs-var">v1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680964106"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964106"><span class="hs-identifier hs-var">v2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Var -&gt; Var -&gt; RuleMatchEnv
</span><a href="GHC.Core.Rules.html#rnMatchBndr2"><span class="hs-identifier hs-var">rnMatchBndr2</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964108"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964121"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964107"><span class="hs-identifier hs-var">v1</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964106"><span class="hs-identifier hs-var">v2</span></a></span><span>
</span><span id="line-898"></span><span>
</span><span id="line-899"></span><span class="annot"><a href="GHC.Core.Rules.html#match_alts"><span class="hs-identifier hs-var">match_alts</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><span class="hs-identifier">_</span></span><span>
</span><span id="line-900"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-901"></span><span>
</span><span id="line-902"></span><span class="hs-comment">------------------------------------------</span><span>
</span><span id="line-903"></span><span class="annot"><a href="GHC.Core.Rules.html#okToFloat"><span class="hs-identifier hs-type">okToFloat</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html#RnEnv2"><span class="hs-identifier hs-type">RnEnv2</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html#VarSet"><span class="hs-identifier hs-type">VarSet</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-904"></span><span id="okToFloat"><span class="annot"><span class="annottext">okToFloat :: RnEnv2 -&gt; VarSet -&gt; Bool
</span><a href="GHC.Core.Rules.html#okToFloat"><span class="hs-identifier hs-var hs-var">okToFloat</span></a></span></span><span> </span><span id="local-6989586621680964105"><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964105"><span class="hs-identifier hs-var">rn_env</span></a></span></span><span> </span><span id="local-6989586621680964104"><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680964104"><span class="hs-identifier hs-var">bind_fvs</span></a></span></span><span>
</span><span id="line-905"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Var -&gt; Bool) -&gt; VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#allVarSet"><span class="hs-identifier hs-var">allVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="#local-6989586621680964102"><span class="hs-identifier hs-var">not_captured</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680964104"><span class="hs-identifier hs-var">bind_fvs</span></a></span><span>
</span><span id="line-906"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-907"></span><span>    </span><span id="local-6989586621680964102"><span class="annot"><span class="annottext">not_captured :: Var -&gt; Bool
</span><a href="#local-6989586621680964102"><span class="hs-identifier hs-var hs-var">not_captured</span></a></span></span><span> </span><span id="local-6989586621680964101"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964101"><span class="hs-identifier hs-var">fv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; Bool
</span><a href="GHC.Types.Var.Env.html#inRnEnvR"><span class="hs-identifier hs-var">inRnEnvR</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964105"><span class="hs-identifier hs-var">rn_env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964101"><span class="hs-identifier hs-var">fv</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-908"></span><span>
</span><span id="line-909"></span><span class="hs-comment">------------------------------------------</span><span>
</span><span id="line-910"></span><span class="annot"><a href="GHC.Core.Rules.html#match_var"><span class="hs-identifier hs-type">match_var</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span>
</span><span id="line-911"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-912"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span>                </span><span class="hs-comment">-- Template</span><span>
</span><span id="line-913"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>        </span><span class="hs-comment">-- Target</span><span>
</span><span id="line-914"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-915"></span><span id="match_var"><span class="annot"><span class="annottext">match_var :: RuleMatchEnv -&gt; RuleSubst -&gt; Var -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_var"><span class="hs-identifier hs-var hs-var">match_var</span></a></span></span><span> </span><span id="local-6989586621680964100"><span class="annot"><span class="annottext">renv :: RuleMatchEnv
</span><a href="#local-6989586621680964100"><span class="hs-identifier hs-var">renv</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Rules.html#RV"><span class="hs-identifier hs-type">RV</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rv_tmpls :: RuleMatchEnv -&gt; VarSet
</span><a href="GHC.Core.Rules.html#rv_tmpls"><span class="hs-identifier hs-var">rv_tmpls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964099"><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680964099"><span class="hs-identifier hs-var">tmpls</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_lcl :: RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var">rv_lcl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964098"><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964098"><span class="hs-identifier hs-var">rn_env</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_fltR :: RuleMatchEnv -&gt; Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var">rv_fltR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964097"><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680964097"><span class="hs-identifier hs-var">flt_env</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-916"></span><span>          </span><span id="local-6989586621680964096"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964096"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964095"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964095"><span class="hs-identifier hs-var">v1</span></a></span></span><span> </span><span id="local-6989586621680964094"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964094"><span class="hs-identifier hs-var">e2</span></a></span></span><span>
</span><span id="line-917"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964093"><span class="hs-identifier hs-var">v1'</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680964099"><span class="hs-identifier hs-var">tmpls</span></a></span><span>
</span><span id="line-918"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Var -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_tmpl_var"><span class="hs-identifier hs-var">match_tmpl_var</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964100"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964096"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964093"><span class="hs-identifier hs-var">v1'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964094"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-919"></span><span>
</span><span id="line-920"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>   </span><span class="hs-comment">-- v1' is not a template variable; check for an exact match with e2</span><span>
</span><span id="line-921"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964094"><span class="hs-identifier hs-var">e2</span></a></span><span> </span><span class="hs-keyword">of</span><span>  </span><span class="hs-comment">-- Remember, envR of rn_env is disjoint from rv_fltR</span><span>
</span><span id="line-922"></span><span>       </span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680964090"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964090"><span class="hs-identifier hs-var">v2</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964093"><span class="hs-identifier hs-var">v1'</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; Var -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; Var
</span><a href="GHC.Types.Var.Env.html#rnOccR"><span class="hs-identifier hs-var">rnOccR</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964098"><span class="hs-identifier hs-var">rn_env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964090"><span class="hs-identifier hs-var">v2</span></a></span><span>
</span><span id="line-923"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964096"><span class="hs-identifier hs-var">subst</span></a></span><span>
</span><span id="line-924"></span><span>
</span><span id="line-925"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680964088"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964088"><span class="hs-identifier hs-var">v2'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Subst -&gt; Var -&gt; CoreExpr
Subst -&gt; Var -&gt; CoreExpr
</span><a href="GHC.Core.Subst.html#lookupIdSubst"><span class="hs-identifier hs-var">lookupIdSubst</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680964097"><span class="hs-identifier hs-var">flt_env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964090"><span class="hs-identifier hs-var">v2</span></a></span><span>
</span><span id="line-926"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964093"><span class="hs-identifier hs-var">v1'</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; Var -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964088"><span class="hs-identifier hs-var">v2'</span></a></span><span>
</span><span id="line-927"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964096"><span class="hs-identifier hs-var">subst</span></a></span><span>
</span><span id="line-928"></span><span>
</span><span id="line-929"></span><span>       </span><span class="annot"><span class="annottext">CoreExpr
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-930"></span><span>
</span><span id="line-931"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-932"></span><span>    </span><span id="local-6989586621680964093"><span class="annot"><span class="annottext">v1' :: Var
</span><a href="#local-6989586621680964093"><span class="hs-identifier hs-var hs-var">v1'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; Var
</span><a href="GHC.Types.Var.Env.html#rnOccL"><span class="hs-identifier hs-var">rnOccL</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964098"><span class="hs-identifier hs-var">rn_env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964095"><span class="hs-identifier hs-var">v1</span></a></span><span>
</span><span id="line-933"></span><span>        </span><span class="hs-comment">-- If the template is</span><span>
</span><span id="line-934"></span><span>        </span><span class="hs-comment">--      forall x. f x (\x -&gt; x) = ...</span><span>
</span><span id="line-935"></span><span>        </span><span class="hs-comment">-- Then the x inside the lambda isn't the</span><span>
</span><span id="line-936"></span><span>        </span><span class="hs-comment">-- template x, so we must rename first!</span><span>
</span><span id="line-937"></span><span>
</span><span id="line-938"></span><span class="hs-comment">------------------------------------------</span><span>
</span><span id="line-939"></span><span class="annot"><a href="GHC.Core.Rules.html#match_tmpl_var"><span class="hs-identifier hs-type">match_tmpl_var</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span>
</span><span id="line-940"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-941"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span>                </span><span class="hs-comment">-- Template</span><span>
</span><span id="line-942"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>              </span><span class="hs-comment">-- Target</span><span>
</span><span id="line-943"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-944"></span><span>
</span><span id="line-945"></span><span id="match_tmpl_var"><span class="annot"><span class="annottext">match_tmpl_var :: RuleMatchEnv -&gt; RuleSubst -&gt; Var -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_tmpl_var"><span class="hs-identifier hs-var hs-var">match_tmpl_var</span></a></span></span><span> </span><span id="local-6989586621680964085"><span class="annot"><span class="annottext">renv :: RuleMatchEnv
</span><a href="#local-6989586621680964085"><span class="hs-identifier hs-var">renv</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Rules.html#RV"><span class="hs-identifier hs-type">RV</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rv_lcl :: RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var">rv_lcl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964084"><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964084"><span class="hs-identifier hs-var">rn_env</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_fltR :: RuleMatchEnv -&gt; Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var">rv_fltR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964083"><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680964083"><span class="hs-identifier hs-var">flt_env</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-946"></span><span>               </span><span id="local-6989586621680964082"><span class="annot"><span class="annottext">subst :: RuleSubst
</span><a href="#local-6989586621680964082"><span class="hs-identifier hs-var">subst</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Rules.html#RS"><span class="hs-identifier hs-type">RS</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rs_id_subst :: RuleSubst -&gt; IdSubstEnv
</span><a href="GHC.Core.Rules.html#rs_id_subst"><span class="hs-identifier hs-var">rs_id_subst</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964081"><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680964081"><span class="hs-identifier hs-var">id_subst</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rs_bndrs :: RuleSubst -&gt; VarSet
</span><a href="GHC.Core.Rules.html#rs_bndrs"><span class="hs-identifier hs-var">rs_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680964080"><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680964080"><span class="hs-identifier hs-var">let_bndrs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-947"></span><span>               </span><span id="local-6989586621680964079"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964079"><span class="hs-identifier hs-var">v1'</span></a></span></span><span> </span><span id="local-6989586621680964078"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964078"><span class="hs-identifier hs-var">e2</span></a></span></span><span>
</span><span id="line-948"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">(Var -&gt; Bool) -&gt; [Var] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RnEnv2 -&gt; Var -&gt; Bool
</span><a href="GHC.Types.Var.Env.html#inRnEnvR"><span class="hs-identifier hs-var">inRnEnvR</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964084"><span class="hs-identifier hs-var">rn_env</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; [Var]
</span><a href="GHC.Core.FVs.html#exprFreeVarsList"><span class="hs-identifier hs-var">exprFreeVarsList</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964078"><span class="hs-identifier hs-var">e2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-949"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>     </span><span class="hs-comment">-- Occurs check failure</span><span>
</span><span id="line-950"></span><span>                </span><span class="hs-comment">-- e.g. match forall a. (\x-&gt; a x) against (\y. y y)</span><span>
</span><span id="line-951"></span><span>
</span><span id="line-952"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680964076"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964076"><span class="hs-identifier hs-var">e1'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv -&gt; Var -&gt; Maybe CoreExpr
forall a. VarEnv a -&gt; Var -&gt; Maybe a
</span><a href="GHC.Types.Var.Env.html#lookupVarEnv"><span class="hs-identifier hs-var">lookupVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680964081"><span class="hs-identifier hs-var">id_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964079"><span class="hs-identifier hs-var">v1'</span></a></span><span>
</span><span id="line-953"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; CoreExpr -&gt; CoreExpr -&gt; Bool
</span><a href="GHC.Core.Utils.html#eqExpr"><span class="hs-identifier hs-var">eqExpr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RnEnv2 -&gt; InScopeSet
</span><a href="GHC.Types.Var.Env.html#rnInScopeSet"><span class="hs-identifier hs-var">rnInScopeSet</span></a></span><span> </span><span class="annot"><span class="annottext">RnEnv2
</span><a href="#local-6989586621680964084"><span class="hs-identifier hs-var">rn_env</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964076"><span class="hs-identifier hs-var">e1'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964075"><span class="hs-identifier hs-var">e2'</span></a></span><span>
</span><span id="line-954"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964082"><span class="hs-identifier hs-var">subst</span></a></span><span>
</span><span id="line-955"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Maybe RuleSubst
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-956"></span><span>
</span><span id="line-957"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-958"></span><span>  </span><span class="hs-glyph">=</span><span>             </span><span class="hs-comment">-- Note [Matching variable types]</span><span>
</span><span id="line-959"></span><span>                </span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-960"></span><span>                </span><span class="hs-comment">-- However, we must match the *types*; e.g.</span><span>
</span><span id="line-961"></span><span>                </span><span class="hs-comment">--   forall (c::Char-&gt;Int) (x::Char).</span><span>
</span><span id="line-962"></span><span>                </span><span class="hs-comment">--      f (c x) = &quot;RULE FIRED&quot;</span><span>
</span><span id="line-963"></span><span>                </span><span class="hs-comment">-- We must only match on args that have the right type</span><span>
</span><span id="line-964"></span><span>                </span><span class="hs-comment">-- It's actually quite difficult to come up with an example that shows</span><span>
</span><span id="line-965"></span><span>                </span><span class="hs-comment">-- you need type matching, esp since matching is left-to-right, so type</span><span>
</span><span id="line-966"></span><span>                </span><span class="hs-comment">-- args get matched first.  But it's possible (e.g. simplrun008) and</span><span>
</span><span id="line-967"></span><span>                </span><span class="hs-comment">-- this is the Right Thing to do</span><span>
</span><span id="line-968"></span><span>    </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964074"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964074"><span class="hs-identifier hs-var">subst'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RuleSubst -&gt; Type -&gt; Type -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_ty"><span class="hs-identifier hs-var">match_ty</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964085"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964082"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964079"><span class="hs-identifier hs-var">v1'</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; Type
</span><a href="GHC.Core.Utils.html#exprType"><span class="hs-identifier hs-var">exprType</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964078"><span class="hs-identifier hs-var">e2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-969"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964074"><span class="hs-identifier hs-var">subst'</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rs_id_subst :: IdSubstEnv
</span><a href="GHC.Core.Rules.html#rs_id_subst"><span class="hs-identifier hs-var">rs_id_subst</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680964072"><span class="hs-identifier hs-var">id_subst'</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-970"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-971"></span><span>    </span><span class="hs-comment">-- e2' is the result of applying flt_env to e2</span><span>
</span><span id="line-972"></span><span>    </span><span id="local-6989586621680964075"><span class="annot"><span class="annottext">e2' :: CoreExpr
</span><a href="#local-6989586621680964075"><span class="hs-identifier hs-var hs-var">e2'</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#isEmptyVarSet"><span class="hs-identifier hs-var">isEmptyVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680964080"><span class="hs-identifier hs-var">let_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964078"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-973"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Subst -&gt; CoreExpr -&gt; CoreExpr
Subst -&gt; CoreExpr -&gt; CoreExpr
</span><a href="GHC.Core.Subst.html#substExpr"><span class="hs-identifier hs-var">substExpr</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680964083"><span class="hs-identifier hs-var">flt_env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964078"><span class="hs-identifier hs-var">e2</span></a></span><span>
</span><span id="line-974"></span><span>
</span><span id="line-975"></span><span>    </span><span id="local-6989586621680964072"><span class="annot"><span class="annottext">id_subst' :: IdSubstEnv
</span><a href="#local-6989586621680964072"><span class="hs-identifier hs-var hs-var">id_subst'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv -&gt; Var -&gt; CoreExpr -&gt; IdSubstEnv
forall a. VarEnv a -&gt; Var -&gt; a -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#extendVarEnv"><span class="hs-identifier hs-var">extendVarEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleSubst -&gt; IdSubstEnv
</span><a href="GHC.Core.Rules.html#rs_id_subst"><span class="hs-identifier hs-var hs-var">rs_id_subst</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964082"><span class="hs-identifier hs-var">subst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964079"><span class="hs-identifier hs-var">v1'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964075"><span class="hs-identifier hs-var">e2'</span></a></span><span>
</span><span id="line-976"></span><span>         </span><span class="hs-comment">-- No further renaming to do on e2',</span><span>
</span><span id="line-977"></span><span>         </span><span class="hs-comment">-- because no free var of e2' is in the rnEnvR of the envt</span><span>
</span><span id="line-978"></span><span>
</span><span id="line-979"></span><span class="hs-comment">------------------------------------------</span><span>
</span><span id="line-980"></span><span class="annot"><a href="GHC.Core.Rules.html#match_ty"><span class="hs-identifier hs-type">match_ty</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleMatchEnv"><span class="hs-identifier hs-type">RuleMatchEnv</span></a></span><span>
</span><span id="line-981"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-982"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>                </span><span class="hs-comment">-- Template</span><span>
</span><span id="line-983"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>                </span><span class="hs-comment">-- Target</span><span>
</span><span id="line-984"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleSubst"><span class="hs-identifier hs-type">RuleSubst</span></a></span><span>
</span><span id="line-985"></span><span class="hs-comment">-- Matching Core types: use the matcher in GHC.Tc.Utils.TcType.</span><span>
</span><span id="line-986"></span><span class="hs-comment">-- Notice that we treat newtypes as opaque.  For example, suppose</span><span>
</span><span id="line-987"></span><span class="hs-comment">-- we have a specialised version of a function at a newtype, say</span><span>
</span><span id="line-988"></span><span class="hs-comment">--      newtype T = MkT Int</span><span>
</span><span id="line-989"></span><span class="hs-comment">-- We only want to replace (f T) with f', not (f Int).</span><span>
</span><span id="line-990"></span><span>
</span><span id="line-991"></span><span id="match_ty"><span class="annot"><span class="annottext">match_ty :: RuleMatchEnv -&gt; RuleSubst -&gt; Type -&gt; Type -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match_ty"><span class="hs-identifier hs-var hs-var">match_ty</span></a></span></span><span> </span><span id="local-6989586621680964067"><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964067"><span class="hs-identifier hs-var">renv</span></a></span></span><span> </span><span id="local-6989586621680964066"><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964066"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span id="local-6989586621680964065"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964065"><span class="hs-identifier hs-var">ty1</span></a></span></span><span> </span><span id="local-6989586621680964064"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964064"><span class="hs-identifier hs-var">ty2</span></a></span></span><span>
</span><span id="line-992"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680964063"><span class="annot"><span class="annottext">TvSubstEnv
</span><a href="#local-6989586621680964063"><span class="hs-identifier hs-var">tv_subst'</span></a></span></span><span>
</span><span id="line-993"></span><span>            </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; RnEnv2 -&gt; TvSubstEnv -&gt; Type -&gt; Type -&gt; Maybe TvSubstEnv
</span><a href="GHC.Core.Unify.html#ruleMatchTyKiX"><span class="hs-identifier hs-var">Unify.ruleMatchTyKiX</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; VarSet
</span><a href="GHC.Core.Rules.html#rv_tmpls"><span class="hs-identifier hs-var hs-var">rv_tmpls</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964067"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleMatchEnv -&gt; RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var hs-var">rv_lcl</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680964067"><span class="hs-identifier hs-var">renv</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">TvSubstEnv
</span><a href="#local-6989586621680964062"><span class="hs-identifier hs-var">tv_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964065"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680964064"><span class="hs-identifier hs-var">ty2</span></a></span><span>
</span><span id="line-994"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; Maybe RuleSubst
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964066"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rs_tv_subst :: TvSubstEnv
</span><a href="GHC.Core.Rules.html#rs_tv_subst"><span class="hs-identifier hs-var">rs_tv_subst</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TvSubstEnv
</span><a href="#local-6989586621680964063"><span class="hs-identifier hs-var">tv_subst'</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-995"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-996"></span><span>    </span><span id="local-6989586621680964062"><span class="annot"><span class="annottext">tv_subst :: TvSubstEnv
</span><a href="#local-6989586621680964062"><span class="hs-identifier hs-var hs-var">tv_subst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleSubst -&gt; TvSubstEnv
</span><a href="GHC.Core.Rules.html#rs_tv_subst"><span class="hs-identifier hs-var hs-var">rs_tv_subst</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="#local-6989586621680964066"><span class="hs-identifier hs-var">subst</span></a></span><span>
</span><span id="line-997"></span><span>
</span><span id="line-998"></span><span class="hs-comment">{-
Note [Expanding variables]
~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is another Very Important rule: if the term being matched is a
variable, we expand it so long as its unfolding is &quot;expandable&quot;. (Its
occurrence information is not necessarily up to date, so we don't use
it.)  By &quot;expandable&quot; we mean a WHNF or a &quot;constructor-like&quot; application.
This is the key reason for &quot;constructor-like&quot; Ids.  If we have
     {-# NOINLINE [1] CONLIKE g #-}
     {-# RULE f (g x) = h x #-}
then in the term
   let v = g 3 in ....(f v)....
we want to make the rule fire, to replace (f v) with (h 3).

Note [Do not expand locally-bound variables]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do *not* expand locally-bound variables, else there's a worry that the
unfolding might mention variables that are themselves renamed.
Example
          case x of y { (p,q) -&gt; ...y... }
Don't expand 'y' to (p,q) because p,q might themselves have been
renamed.  Essentially we only expand unfoldings that are &quot;outside&quot;
the entire match.

Hence, (a) the guard (not (isLocallyBoundR v2))
       (b) when we expand we nuke the renaming envt (nukeRnEnvR).

Note [Tick annotations in RULE matching]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We used to unconditionally look through ticks in both template and
expression being matched. This is actually illegal for counting or
cost-centre-scoped ticks, because we have no place to put them without
changing entry counts and/or costs. So now we just fail the match in
these cases.

On the other hand, where we are allowed to insert new cost into the
tick scope, we can float them upwards to the rule application site.

Moreover, we may encounter ticks in the template of a rule. There are a few
ways in which these may be introduced (e.g. #18162, #17619). Such ticks are
ignored by the matcher. See Note [Simplifying rules] in
GHC.Core.Opt.Simplify.Utils for details.

cf Note [Tick annotations in call patterns] in GHC.Core.Opt.SpecConstr

Note [Matching lets]
~~~~~~~~~~~~~~~~~~~~
Matching a let-expression.  Consider
        RULE forall x.  f (g x) = &lt;rhs&gt;
and target expression
        f (let { w=R } in g E))
Then we'd like the rule to match, to generate
        let { w=R } in (\x. &lt;rhs&gt;) E
In effect, we want to float the let-binding outward, to enable
the match to happen.  This is the WHOLE REASON for accumulating
bindings in the RuleSubst

We can only do this if the free variables of R are not bound by the
part of the target expression outside the let binding; e.g.
        f (\v. let w = v+1 in g E)
Here we obviously cannot float the let-binding for w.  Hence the
use of okToFloat.

There are a couple of tricky points.
  (a) What if floating the binding captures a variable?
        f (let v = x+1 in v) v
      --&gt; NOT!
        let v = x+1 in f (x+1) v

  (b) What if two non-nested let bindings bind the same variable?
        f (let v = e1 in b1) (let v = e2 in b2)
      --&gt; NOT!
        let v = e1 in let v = e2 in (f b2 b2)
      See testsuite test &quot;RuleFloatLet&quot;.

Our cunning plan is this:
  * Along with the growing substitution for template variables
    we maintain a growing set of floated let-bindings (rs_binds)
    plus the set of variables thus bound.

  * The RnEnv2 in the MatchEnv binds only the local binders
    in the term (lambdas, case)

  * When we encounter a let in the term to be matched, we
    check that does not mention any locally bound (lambda, case)
    variables.  If so we fail

  * We use GHC.Core.Subst.substBind to freshen the binding, using an
    in-scope set that is the original in-scope variables plus the
    rs_bndrs (currently floated let-bindings).  So in (a) above
    we'll freshen the 'v' binding; in (b) above we'll freshen
    the *second* 'v' binding.

  * We apply that freshening substitution, in a lexically-scoped
    way to the term, although lazily; this is the rv_fltR field.


Note [Matching cases]
~~~~~~~~~~~~~~~~~~~~~
{- NOTE: This idea is currently disabled.  It really only works if
         the primops involved are OkForSpeculation, and, since
         they have side effects readIntOfAddr and touch are not.
         Maybe we'll get back to this later .  -}

Consider
   f (case readIntOffAddr# p# i# realWorld# of { (# s#, n# #) -&gt;
      case touch# fp s# of { _ -&gt;
      I# n# } } )
This happened in a tight loop generated by stream fusion that
Roman encountered.  We'd like to treat this just like the let
case, because the primops concerned are ok-for-speculation.
That is, we'd like to behave as if it had been
   case readIntOffAddr# p# i# realWorld# of { (# s#, n# #) -&gt;
   case touch# fp s# of { _ -&gt;
   f (I# n# } } )

Note [Lookup in-scope]
~~~~~~~~~~~~~~~~~~~~~~
Consider this example
        foo :: Int -&gt; Maybe Int -&gt; Int
        foo 0 (Just n) = n
        foo m (Just n) = foo (m-n) (Just n)

SpecConstr sees this fragment:

        case w_smT of wild_Xf [Just A] {
          Data.Maybe.Nothing -&gt; lvl_smf;
          Data.Maybe.Just n_acT [Just S(L)] -&gt;
            case n_acT of wild1_ams [Just A] { GHC.Base.I# y_amr [Just L] -&gt;
              $wfoo_smW (GHC.Prim.-# ds_Xmb y_amr) wild_Xf
            }};

and correctly generates the rule

        RULES: &quot;SC:$wfoo1&quot; [0] __forall {y_amr [Just L] :: GHC.Prim.Int#
                                          sc_snn :: GHC.Prim.Int#}
          $wfoo_smW sc_snn (Data.Maybe.Just @ GHC.Base.Int (GHC.Base.I# y_amr))
          = $s$wfoo_sno y_amr sc_snn ;]

BUT we must ensure that this rule matches in the original function!
Note that the call to $wfoo is
            $wfoo_smW (GHC.Prim.-# ds_Xmb y_amr) wild_Xf

During matching we expand wild_Xf to (Just n_acT).  But then we must also
expand n_acT to (I# y_amr).  And we can only do that if we look up n_acT
in the in-scope set, because in wild_Xf's unfolding it won't have an unfolding
at all.

That is why the 'lookupRnInScope' call in the (Var v2) case of 'match'
is so important.


************************************************************************
*                                                                      *
                   Rule-check the program
*                                                                      *
************************************************************************

   We want to know what sites have rules that could have fired but didn't.
   This pass runs over the tree (without changing it) and reports such.
-}</span><span>
</span><span id="line-1160"></span><span>
</span><span id="line-1161"></span><span class="hs-comment">-- | Report partial matches for rules beginning with the specified</span><span>
</span><span id="line-1162"></span><span class="hs-comment">-- string for the purposes of error reporting</span><span>
</span><span id="line-1163"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheckProgram"><span class="hs-identifier hs-type">ruleCheckProgram</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleOpts"><span class="hs-identifier hs-type">RuleOpts</span></a></span><span>                    </span><span class="hs-comment">-- ^ Rule options</span><span>
</span><span id="line-1164"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#CompilerPhase"><span class="hs-identifier hs-type">CompilerPhase</span></a></span><span>               </span><span class="hs-comment">-- ^ Rule activation test</span><span>
</span><span id="line-1165"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>                      </span><span class="hs-comment">-- ^ Rule pattern</span><span>
</span><span id="line-1166"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>          </span><span class="hs-comment">-- ^ Rules for an Id</span><span>
</span><span id="line-1167"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreProgram"><span class="hs-identifier hs-type">CoreProgram</span></a></span><span>                 </span><span class="hs-comment">-- ^ Bindings to check in</span><span>
</span><span id="line-1168"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>                        </span><span class="hs-comment">-- ^ Resulting check message</span><span>
</span><span id="line-1169"></span><span id="ruleCheckProgram"><span class="annot"><span class="annottext">ruleCheckProgram :: RuleOpts
-&gt; CompilerPhase
-&gt; String
-&gt; (Var -&gt; [CoreRule])
-&gt; [CoreBind]
-&gt; SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckProgram"><span class="hs-identifier hs-var hs-var">ruleCheckProgram</span></a></span></span><span> </span><span id="local-6989586621680964060"><span class="annot"><span class="annottext">RuleOpts
</span><a href="#local-6989586621680964060"><span class="hs-identifier hs-var">ropts</span></a></span></span><span> </span><span id="local-6989586621680964059"><span class="annot"><span class="annottext">CompilerPhase
</span><a href="#local-6989586621680964059"><span class="hs-identifier hs-var">phase</span></a></span></span><span> </span><span id="local-6989586621680964058"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680964058"><span class="hs-identifier hs-var">rule_pat</span></a></span></span><span> </span><span id="local-6989586621680964057"><span class="annot"><span class="annottext">Var -&gt; [CoreRule]
</span><a href="#local-6989586621680964057"><span class="hs-identifier hs-var">rules</span></a></span></span><span> </span><span id="local-6989586621680964056"><span class="annot"><span class="annottext">[CoreBind]
</span><a href="#local-6989586621680964056"><span class="hs-identifier hs-var">binds</span></a></span></span><span>
</span><span id="line-1170"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bag SDoc -&gt; Bool
forall a. Bag a -&gt; Bool
</span><a href="GHC.Data.Bag.html#isEmptyBag"><span class="hs-identifier hs-var">isEmptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Bag SDoc
</span><a href="#local-6989586621680964054"><span class="hs-identifier hs-var">results</span></a></span><span>
</span><span id="line-1171"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Rule check results: no rule application sites&quot;</span></span><span>
</span><span id="line-1172"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1173"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Rule check results:&quot;</span></span><span class="hs-special">,</span><span>
</span><span id="line-1174"></span><span>          </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680964053"><span class="hs-identifier hs-var">line</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-1175"></span><span>          </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680964052"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680964053"><span class="hs-identifier hs-var">line</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680964052"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680964052"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Bag SDoc -&gt; [SDoc]
forall a. Bag a -&gt; [a]
</span><a href="GHC.Data.Bag.html#bagToList"><span class="hs-identifier hs-var">bagToList</span></a></span><span> </span><span class="annot"><span class="annottext">Bag SDoc
</span><a href="#local-6989586621680964054"><span class="hs-identifier hs-var">results</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-1176"></span><span>         </span><span class="hs-special">]</span><span>
</span><span id="line-1177"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1178"></span><span>    </span><span id="local-6989586621680964050"><span class="annot"><span class="annottext">env :: RuleCheckEnv
</span><a href="#local-6989586621680964050"><span class="hs-identifier hs-var hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv :: (Activation -&gt; Bool)
-&gt; (Var -&gt; Unfolding)
-&gt; String
-&gt; (Var -&gt; [CoreRule])
-&gt; RuleOpts
-&gt; RuleCheckEnv
</span><a href="GHC.Core.Rules.html#RuleCheckEnv"><span class="hs-identifier hs-type">RuleCheckEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rc_is_active :: Activation -&gt; Bool
</span><a href="GHC.Core.Rules.html#rc_is_active"><span class="hs-identifier hs-var">rc_is_active</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase -&gt; Activation -&gt; Bool
</span><a href="GHC.Types.Basic.html#isActive"><span class="hs-identifier hs-var">isActive</span></a></span><span> </span><span class="annot"><span class="annottext">CompilerPhase
</span><a href="#local-6989586621680964059"><span class="hs-identifier hs-var">phase</span></a></span><span>
</span><span id="line-1179"></span><span>                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rc_id_unf :: Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rc_id_unf"><span class="hs-identifier hs-var">rc_id_unf</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span>     </span><span class="hs-comment">-- Not quite right</span><span>
</span><span id="line-1180"></span><span>                                                        </span><span class="hs-comment">-- Should use activeUnfolding</span><span>
</span><span id="line-1181"></span><span>                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rc_pattern :: String
</span><a href="GHC.Core.Rules.html#rc_pattern"><span class="hs-identifier hs-var">rc_pattern</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680964058"><span class="hs-identifier hs-var">rule_pat</span></a></span><span>
</span><span id="line-1182"></span><span>                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rc_rules :: Var -&gt; [CoreRule]
</span><a href="GHC.Core.Rules.html#rc_rules"><span class="hs-identifier hs-var">rc_rules</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; [CoreRule]
</span><a href="#local-6989586621680964057"><span class="hs-identifier hs-var">rules</span></a></span><span>
</span><span id="line-1183"></span><span>                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rc_ropts :: RuleOpts
</span><a href="GHC.Core.Rules.html#rc_ropts"><span class="hs-identifier hs-var">rc_ropts</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleOpts
</span><a href="#local-6989586621680964060"><span class="hs-identifier hs-var">ropts</span></a></span><span>
</span><span id="line-1184"></span><span>                       </span><span class="hs-special">}</span><span>
</span><span id="line-1185"></span><span>    </span><span id="local-6989586621680964054"><span class="annot"><span class="annottext">results :: Bag SDoc
</span><a href="#local-6989586621680964054"><span class="hs-identifier hs-var hs-var">results</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Bag SDoc] -&gt; Bag SDoc
forall a. [Bag a] -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionManyBags"><span class="hs-identifier hs-var">unionManyBags</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(CoreBind -&gt; Bag SDoc) -&gt; [CoreBind] -&gt; [Bag SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreBind -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckBind"><span class="hs-identifier hs-var">ruleCheckBind</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964050"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[CoreBind]
</span><a href="#local-6989586621680964056"><span class="hs-identifier hs-var">binds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1186"></span><span>    </span><span id="local-6989586621680964053"><span class="annot"><span class="annottext">line :: SDoc
</span><a href="#local-6989586621680964053"><span class="hs-identifier hs-var hs-var">line</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Arity -&gt; Char -&gt; String
forall a. Arity -&gt; a -&gt; [a]
</span><a href="../../base/src/GHC.List.html#replicate"><span class="hs-identifier hs-var">replicate</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">20</span></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'-'</span></span><span class="hs-special">)</span><span>
</span><span id="line-1187"></span><span>
</span><span id="line-1188"></span><span class="hs-keyword">data</span><span> </span><span id="RuleCheckEnv"><span class="annot"><a href="GHC.Core.Rules.html#RuleCheckEnv"><span class="hs-identifier hs-var">RuleCheckEnv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="RuleCheckEnv"><span class="annot"><a href="GHC.Core.Rules.html#RuleCheckEnv"><span class="hs-identifier hs-var">RuleCheckEnv</span></a></span></span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-1189"></span><span>    </span><span id="rc_is_active"><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Activation -&gt; Bool
</span><a href="GHC.Core.Rules.html#rc_is_active"><span class="hs-identifier hs-var hs-var">rc_is_active</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Activation"><span class="hs-identifier hs-type">Activation</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">,</span><span>
</span><span id="line-1190"></span><span>    </span><span id="rc_id_unf"><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rc_id_unf"><span class="hs-identifier hs-var hs-var">rc_id_unf</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#IdUnfoldingFun"><span class="hs-identifier hs-type">IdUnfoldingFun</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-1191"></span><span>    </span><span id="rc_pattern"><span class="annot"><span class="annottext">RuleCheckEnv -&gt; String
</span><a href="GHC.Core.Rules.html#rc_pattern"><span class="hs-identifier hs-var hs-var">rc_pattern</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-1192"></span><span>    </span><span id="rc_rules"><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Var -&gt; [CoreRule]
</span><a href="GHC.Core.Rules.html#rc_rules"><span class="hs-identifier hs-var hs-var">rc_rules</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span>
</span><span id="line-1193"></span><span>    </span><span id="rc_ropts"><span class="annot"><span class="annottext">RuleCheckEnv -&gt; RuleOpts
</span><a href="GHC.Core.Rules.html#rc_ropts"><span class="hs-identifier hs-var hs-var">rc_ropts</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#RuleOpts"><span class="hs-identifier hs-type">RuleOpts</span></a></span><span>
</span><span id="line-1194"></span><span class="hs-special">}</span><span>
</span><span id="line-1195"></span><span>
</span><span id="line-1196"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheckBind"><span class="hs-identifier hs-type">ruleCheckBind</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleCheckEnv"><span class="hs-identifier hs-type">RuleCheckEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreBind"><span class="hs-identifier hs-type">CoreBind</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-1197"></span><span>   </span><span class="hs-comment">-- The Bag returned has one SDoc for each call site found</span><span>
</span><span id="line-1198"></span><span id="ruleCheckBind"><span class="annot"><span class="annottext">ruleCheckBind :: RuleCheckEnv -&gt; CoreBind -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckBind"><span class="hs-identifier hs-var hs-var">ruleCheckBind</span></a></span></span><span> </span><span id="local-6989586621680964038"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964038"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-type">NonRec</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964036"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964036"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964038"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964036"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-1199"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheckBind"><span class="hs-identifier hs-var">ruleCheckBind</span></a></span><span> </span><span id="local-6989586621680964034"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964034"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-type">Rec</span></a></span><span> </span><span id="local-6989586621680964032"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680964032"><span class="hs-identifier hs-var">prs</span></a></span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Bag SDoc] -&gt; Bag SDoc
forall a. [Bag a] -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionManyBags"><span class="hs-identifier hs-var">unionManyBags</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964034"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964031"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621680964031"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964031"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680964032"><span class="hs-identifier hs-var">prs</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1200"></span><span>
</span><span id="line-1201"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-type">ruleCheck</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleCheckEnv"><span class="hs-identifier hs-type">RuleCheckEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-1202"></span><span id="ruleCheck"><span class="annot"><span class="annottext">ruleCheck :: RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var hs-var">ruleCheck</span></a></span></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><span class="hs-identifier">_</span></span><span>   </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag SDoc
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span>
</span><span id="line-1203"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><span class="hs-identifier">_</span></span><span>   </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span class="annot"><span class="annottext">Literal
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag SDoc
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span>
</span><span id="line-1204"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><span class="hs-identifier">_</span></span><span>   </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag SDoc
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span>
</span><span id="line-1205"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><span class="hs-identifier">_</span></span><span>   </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag SDoc
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span>
</span><span id="line-1206"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span id="local-6989586621680964029"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964029"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680964028"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964028"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621680964027"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964027"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; [CoreExpr] -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckApp"><span class="hs-identifier hs-var">ruleCheckApp</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964029"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; CoreExpr -&gt; CoreExpr
forall b. Expr b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#App"><span class="hs-identifier hs-var">App</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964028"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964027"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-1207"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span id="local-6989586621680964025"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964025"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964024"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964024"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964025"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964024"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1208"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span id="local-6989586621680964023"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964023"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680964022"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964022"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964023"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964022"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1209"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span id="local-6989586621680964021"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964021"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span id="local-6989586621680964020"><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964020"><span class="hs-identifier hs-var">bd</span></a></span></span><span> </span><span id="local-6989586621680964019"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964019"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreBind -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckBind"><span class="hs-identifier hs-var">ruleCheckBind</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964021"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680964020"><span class="hs-identifier hs-var">bd</span></a></span><span> </span><span class="annot"><span class="annottext">Bag SDoc -&gt; Bag SDoc -&gt; Bag SDoc
forall a. Bag a -&gt; Bag a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionBags"><span class="hs-operator hs-var">`unionBags`</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964021"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964019"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1210"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span id="local-6989586621680964017"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964017"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964016"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964016"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964017"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964016"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1211"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span id="local-6989586621680964015"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964015"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680964014"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964014"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">Var
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680964013"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964013"><span class="hs-keyword hs-var">as</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964015"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964014"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="annot"><span class="annottext">Bag SDoc -&gt; Bag SDoc -&gt; Bag SDoc
forall a. Bag a -&gt; Bag a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionBags"><span class="hs-operator hs-var">`unionBags`</span></a></span><span>
</span><span id="line-1212"></span><span>                                </span><span class="annot"><span class="annottext">[Bag SDoc] -&gt; Bag SDoc
forall a. [Bag a] -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionManyBags"><span class="hs-identifier hs-var">unionManyBags</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964015"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964012"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[Var]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621680964012"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964012"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680964013"><span class="hs-keyword hs-var">as</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1213"></span><span>
</span><span id="line-1214"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheckApp"><span class="hs-identifier hs-type">ruleCheckApp</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleCheckEnv"><span class="hs-identifier hs-type">RuleCheckEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Expr"><span class="hs-identifier hs-type">Expr</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreBndr"><span class="hs-identifier hs-type">CoreBndr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#Arg"><span class="hs-identifier hs-type">Arg</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreBndr"><span class="hs-identifier hs-type">CoreBndr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-1215"></span><span id="ruleCheckApp"><span class="annot"><span class="annottext">ruleCheckApp :: RuleCheckEnv -&gt; CoreExpr -&gt; [CoreExpr] -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckApp"><span class="hs-identifier hs-var hs-var">ruleCheckApp</span></a></span></span><span> </span><span id="local-6989586621680964010"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964010"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680964009"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964009"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621680964008"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964008"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680964007"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964007"><span class="hs-keyword hs-var">as</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964010"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964008"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">Bag SDoc -&gt; Bag SDoc -&gt; Bag SDoc
forall a. Bag a -&gt; Bag a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionBags"><span class="hs-operator hs-var">`unionBags`</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; [CoreExpr] -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckApp"><span class="hs-identifier hs-var">ruleCheckApp</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964010"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964009"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964008"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">CoreExpr -&gt; [CoreExpr] -&gt; [CoreExpr]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964007"><span class="hs-keyword hs-var">as</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1216"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheckApp"><span class="hs-identifier hs-var">ruleCheckApp</span></a></span><span> </span><span id="local-6989586621680964006"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964006"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680964005"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964005"><span class="hs-identifier hs-var">f</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680964004"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964004"><span class="hs-keyword hs-var">as</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Var -&gt; [CoreExpr] -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckFun"><span class="hs-identifier hs-var">ruleCheckFun</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964006"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680964005"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680964004"><span class="hs-keyword hs-var">as</span></a></span><span>
</span><span id="line-1217"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheckApp"><span class="hs-identifier hs-var">ruleCheckApp</span></a></span><span> </span><span id="local-6989586621680964002"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964002"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680964001"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964001"><span class="hs-identifier hs-var">other</span></a></span></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; CoreExpr -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheck"><span class="hs-identifier hs-var">ruleCheck</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964002"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680964001"><span class="hs-identifier hs-var">other</span></a></span><span>
</span><span id="line-1218"></span><span>
</span><span id="line-1219"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleCheckFun"><span class="hs-identifier hs-type">ruleCheckFun</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleCheckEnv"><span class="hs-identifier hs-type">RuleCheckEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-1220"></span><span class="hs-comment">-- Produce a report for all rules matching the predicate</span><span>
</span><span id="line-1221"></span><span class="hs-comment">-- saying why it doesn't match the specified application</span><span>
</span><span id="line-1222"></span><span>
</span><span id="line-1223"></span><span id="ruleCheckFun"><span class="annot"><span class="annottext">ruleCheckFun :: RuleCheckEnv -&gt; Var -&gt; [CoreExpr] -&gt; Bag SDoc
</span><a href="GHC.Core.Rules.html#ruleCheckFun"><span class="hs-identifier hs-var hs-var">ruleCheckFun</span></a></span></span><span> </span><span id="local-6989586621680964000"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964000"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680963999"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963999"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span id="local-6989586621680963998"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963998"><span class="hs-identifier hs-var">args</span></a></span></span><span>
</span><span id="line-1224"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680963997"><span class="hs-identifier hs-var">name_match_rules</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag SDoc
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span>
</span><span id="line-1225"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Bag SDoc
forall a. a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unitBag"><span class="hs-identifier hs-var">unitBag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Var -&gt; [CoreExpr] -&gt; [CoreRule] -&gt; SDoc
</span><a href="GHC.Core.Rules.html#ruleAppCheck_help"><span class="hs-identifier hs-var">ruleAppCheck_help</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964000"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963999"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963998"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680963997"><span class="hs-identifier hs-var">name_match_rules</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1226"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1227"></span><span>    </span><span id="local-6989586621680963997"><span class="annot"><span class="annottext">name_match_rules :: [CoreRule]
</span><a href="#local-6989586621680963997"><span class="hs-identifier hs-var hs-var">name_match_rules</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreRule -&gt; Bool) -&gt; [CoreRule] -&gt; [CoreRule]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; Bool
</span><a href="#local-6989586621680963994"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Var -&gt; [CoreRule]
</span><a href="GHC.Core.Rules.html#rc_rules"><span class="hs-identifier hs-var hs-var">rc_rules</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964000"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963999"><span class="hs-identifier hs-var">fn</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1228"></span><span>    </span><span id="local-6989586621680963994"><span class="annot"><span class="annottext">match :: CoreRule -&gt; Bool
</span><a href="#local-6989586621680963994"><span class="hs-identifier hs-var hs-var">match</span></a></span></span><span> </span><span id="local-6989586621680963991"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680963991"><span class="hs-identifier hs-var">rule</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; String
</span><a href="GHC.Core.Rules.html#rc_pattern"><span class="hs-identifier hs-var hs-var">rc_pattern</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680964000"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; Bool
forall a. Eq a =&gt; [a] -&gt; [a] -&gt; Bool
</span><a href="../../base/src/Data.OldList.html#isPrefixOf"><span class="hs-operator hs-var">`isPrefixOf`</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName -&gt; String
</span><a href="GHC.Data.FastString.html#unpackFS"><span class="hs-identifier hs-var">unpackFS</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreRule -&gt; RuleName
</span><a href="GHC.Core.html#ruleName"><span class="hs-identifier hs-var">ruleName</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680963991"><span class="hs-identifier hs-var">rule</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1229"></span><span>
</span><span id="line-1230"></span><span class="annot"><a href="GHC.Core.Rules.html#ruleAppCheck_help"><span class="hs-identifier hs-type">ruleAppCheck_help</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Rules.html#RuleCheckEnv"><span class="hs-identifier hs-type">RuleCheckEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-1231"></span><span id="ruleAppCheck_help"><span class="annot"><span class="annottext">ruleAppCheck_help :: RuleCheckEnv -&gt; Var -&gt; [CoreExpr] -&gt; [CoreRule] -&gt; SDoc
</span><a href="GHC.Core.Rules.html#ruleAppCheck_help"><span class="hs-identifier hs-var hs-var">ruleAppCheck_help</span></a></span></span><span> </span><span id="local-6989586621680963988"><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680963988"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680963987"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963987"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span id="local-6989586621680963986"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963986"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680963985"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680963985"><span class="hs-identifier hs-var">rules</span></a></span></span><span>
</span><span id="line-1232"></span><span>  </span><span class="hs-glyph">=</span><span>     </span><span class="hs-comment">-- The rules match the pattern, so we want to print something</span><span>
</span><span id="line-1233"></span><span>    </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Expression:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; [CoreExpr] -&gt; CoreExpr
forall b. Expr b -&gt; [Expr b] -&gt; Expr b
</span><a href="GHC.Core.html#mkApps"><span class="hs-identifier hs-var">mkApps</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; CoreExpr
forall b. Var -&gt; Expr b
</span><a href="GHC.Core.html#Var"><span class="hs-identifier hs-var">Var</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963987"><span class="hs-identifier hs-var">fn</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963986"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-1234"></span><span>          </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(CoreRule -&gt; SDoc) -&gt; [CoreRule] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; SDoc
</span><a href="#local-6989586621680963984"><span class="hs-identifier hs-var">check_rule</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680963985"><span class="hs-identifier hs-var">rules</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-1235"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1236"></span><span>    </span><span id="local-6989586621680963982"><span class="annot"><span class="annottext">n_args :: Arity
</span><a href="#local-6989586621680963982"><span class="hs-identifier hs-var hs-var">n_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreExpr] -&gt; Arity
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Arity
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963986"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-1237"></span><span>    </span><span id="local-6989586621680963978"><span class="annot"><span class="annottext">i_args :: [(CoreExpr, Arity)]
</span><a href="#local-6989586621680963978"><span class="hs-identifier hs-var hs-var">i_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963986"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr] -&gt; [Arity] -&gt; [(CoreExpr, Arity)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-operator hs-var">`zip`</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span class="hs-glyph">::</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">..</span><span class="hs-special">]</span><span>
</span><span id="line-1238"></span><span>    </span><span id="local-6989586621680963977"><span class="annot"><span class="annottext">rough_args :: [Maybe Name]
</span><a href="#local-6989586621680963977"><span class="hs-identifier hs-var hs-var">rough_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreExpr -&gt; Maybe Name) -&gt; [CoreExpr] -&gt; [Maybe Name]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Maybe Name
</span><a href="GHC.Core.Rules.html#roughTopName"><span class="hs-identifier hs-var">roughTopName</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963986"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-1239"></span><span>
</span><span id="line-1240"></span><span>    </span><span id="local-6989586621680963984"><span class="annot"><span class="annottext">check_rule :: CoreRule -&gt; SDoc
</span><a href="#local-6989586621680963984"><span class="hs-identifier hs-var hs-var">check_rule</span></a></span></span><span> </span><span id="local-6989586621680963976"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680963976"><span class="hs-identifier hs-var">rule</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; SDoc
</span><a href="#local-6989586621680963975"><span class="hs-identifier hs-var">rule_herald</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680963976"><span class="hs-identifier hs-var">rule</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#colon"><span class="hs-identifier hs-var">colon</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">RuleOpts -&gt; CoreRule -&gt; SDoc
</span><a href="#local-6989586621680963972"><span class="hs-identifier hs-var">rule_info</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; RuleOpts
</span><a href="GHC.Core.Rules.html#rc_ropts"><span class="hs-identifier hs-var hs-var">rc_ropts</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680963988"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680963976"><span class="hs-identifier hs-var">rule</span></a></span><span>
</span><span id="line-1241"></span><span>
</span><span id="line-1242"></span><span>    </span><span id="local-6989586621680963975"><span class="annot"><span class="annottext">rule_herald :: CoreRule -&gt; SDoc
</span><a href="#local-6989586621680963975"><span class="hs-identifier hs-var hs-var">rule_herald</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#BuiltinRule"><span class="hs-identifier hs-type">BuiltinRule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_name :: CoreRule -&gt; RuleName
</span><a href="GHC.Core.html#ru_name"><span class="hs-identifier hs-var">ru_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680963971"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680963971"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1243"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Builtin rule&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#doubleQuotes"><span class="hs-identifier hs-var">doubleQuotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleName -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ftext"><span class="hs-identifier hs-var">ftext</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680963971"><span class="hs-identifier hs-var">name</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1244"></span><span>    </span><span class="annot"><a href="#local-6989586621680963975"><span class="hs-identifier hs-var">rule_herald</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rule"><span class="hs-identifier hs-type">Rule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_name :: CoreRule -&gt; RuleName
</span><a href="GHC.Core.html#ru_name"><span class="hs-identifier hs-var">ru_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680963970"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680963970"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1245"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Rule&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#doubleQuotes"><span class="hs-identifier hs-var">doubleQuotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleName -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ftext"><span class="hs-identifier hs-var">ftext</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621680963970"><span class="hs-identifier hs-var">name</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1246"></span><span>
</span><span id="line-1247"></span><span>    </span><span id="local-6989586621680963972"><span class="annot"><span class="annottext">rule_info :: RuleOpts -&gt; CoreRule -&gt; SDoc
</span><a href="#local-6989586621680963972"><span class="hs-identifier hs-var hs-var">rule_info</span></a></span></span><span> </span><span id="local-6989586621680963961"><span class="annot"><span class="annottext">RuleOpts
</span><a href="#local-6989586621680963961"><span class="hs-identifier hs-var">opts</span></a></span></span><span> </span><span id="local-6989586621680963960"><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680963960"><span class="hs-identifier hs-var">rule</span></a></span></span><span>
</span><span id="line-1248"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleOpts
-&gt; InScopeEnv
-&gt; (Activation -&gt; Bool)
-&gt; Var
-&gt; [CoreExpr]
-&gt; [Maybe Name]
-&gt; CoreRule
-&gt; Maybe CoreExpr
</span><a href="GHC.Core.Rules.html#matchRule"><span class="hs-identifier hs-var">matchRule</span></a></span><span> </span><span class="annot"><span class="annottext">RuleOpts
</span><a href="#local-6989586621680963961"><span class="hs-identifier hs-var">opts</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InScopeSet
</span><a href="GHC.Types.Var.Env.html#emptyInScopeSet"><span class="hs-identifier hs-var">emptyInScopeSet</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rc_id_unf"><span class="hs-identifier hs-var hs-var">rc_id_unf</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680963988"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1249"></span><span>                              </span><span class="annot"><span class="annottext">Activation -&gt; Bool
</span><a href="GHC.Core.Rules.html#noBlackList"><span class="hs-identifier hs-var">noBlackList</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963987"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963986"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680963977"><span class="hs-identifier hs-var">rough_args</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule
</span><a href="#local-6989586621680963960"><span class="hs-identifier hs-var">rule</span></a></span><span>
</span><span id="line-1250"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;matches (which is very peculiar!)&quot;</span></span><span>
</span><span id="line-1251"></span><span>
</span><span id="line-1252"></span><span>    </span><span class="annot"><a href="#local-6989586621680963972"><span class="hs-identifier hs-var">rule_info</span></a></span><span> </span><span class="annot"><span class="annottext">RuleOpts
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#BuiltinRule"><span class="hs-identifier hs-type">BuiltinRule</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;does not match&quot;</span></span><span>
</span><span id="line-1253"></span><span>
</span><span id="line-1254"></span><span>    </span><span class="annot"><a href="#local-6989586621680963972"><span class="hs-identifier hs-var">rule_info</span></a></span><span> </span><span class="annot"><span class="annottext">RuleOpts
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rule"><span class="hs-identifier hs-type">Rule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ru_act :: CoreRule -&gt; Activation
</span><a href="GHC.Core.html#ru_act"><span class="hs-identifier hs-var">ru_act</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680963958"><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680963958"><span class="hs-identifier hs-var">act</span></a></span></span><span class="hs-special">,</span><span>
</span><span id="line-1255"></span><span>                        </span><span class="annot"><span class="annottext">ru_bndrs :: CoreRule -&gt; [Var]
</span><a href="GHC.Core.html#ru_bndrs"><span class="hs-identifier hs-var">ru_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680963957"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680963957"><span class="hs-identifier hs-var">rule_bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ru_args :: CoreRule -&gt; [CoreExpr]
</span><a href="GHC.Core.html#ru_args"><span class="hs-identifier hs-var">ru_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680963956"><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963956"><span class="hs-identifier hs-var">rule_args</span></a></span></span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1256"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Activation -&gt; Bool
</span><a href="GHC.Core.Rules.html#rc_is_active"><span class="hs-identifier hs-var hs-var">rc_is_active</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680963988"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680963958"><span class="hs-identifier hs-var">act</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;active only in later phase&quot;</span></span><span>
</span><span id="line-1257"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680963982"><span class="hs-identifier hs-var">n_args</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680963954"><span class="hs-identifier hs-var">n_rule_args</span></a></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;too few arguments&quot;</span></span><span>
</span><span id="line-1258"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680963953"><span class="hs-identifier hs-var">n_mismatches</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680963954"><span class="hs-identifier hs-var">n_rule_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;no arguments match&quot;</span></span><span>
</span><span id="line-1259"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680963953"><span class="hs-identifier hs-var">n_mismatches</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;all arguments match (considered individually), but rule as a whole does not&quot;</span></span><span>
</span><span id="line-1260"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;arguments&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[Arity] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680963952"><span class="hs-identifier hs-var">mismatches</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;do not match (1-indexing)&quot;</span></span><span>
</span><span id="line-1261"></span><span>        </span><span class="hs-keyword">where</span><span>
</span><span id="line-1262"></span><span>          </span><span id="local-6989586621680963954"><span class="annot"><span class="annottext">n_rule_args :: Arity
</span><a href="#local-6989586621680963954"><span class="hs-identifier hs-var hs-var">n_rule_args</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreExpr] -&gt; Arity
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Arity
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963956"><span class="hs-identifier hs-var">rule_args</span></a></span><span>
</span><span id="line-1263"></span><span>          </span><span id="local-6989586621680963953"><span class="annot"><span class="annottext">n_mismatches :: Arity
</span><a href="#local-6989586621680963953"><span class="hs-identifier hs-var hs-var">n_mismatches</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Arity] -&gt; Arity
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Arity
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680963952"><span class="hs-identifier hs-var">mismatches</span></a></span><span>
</span><span id="line-1264"></span><span>          </span><span id="local-6989586621680963952"><span class="annot"><span class="annottext">mismatches :: [Arity]
</span><a href="#local-6989586621680963952"><span class="hs-identifier hs-var hs-var">mismatches</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680963949"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680963948"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963948"><span class="hs-identifier hs-var">rule_arg</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680963947"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963947"><span class="hs-identifier hs-var">arg</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680963949"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680963949"><span class="hs-identifier hs-var">i</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963956"><span class="hs-identifier hs-var">rule_args</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
-&gt; [(CoreExpr, Arity)] -&gt; [(CoreExpr, (CoreExpr, Arity))]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-operator hs-var">`zip`</span></a></span><span> </span><span class="annot"><span class="annottext">[(CoreExpr, Arity)]
</span><a href="#local-6989586621680963978"><span class="hs-identifier hs-var">i_args</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-1265"></span><span>                              </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe RuleSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="#local-6989586621680963946"><span class="hs-identifier hs-var">match_fn</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963948"><span class="hs-identifier hs-var">rule_arg</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963947"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-1266"></span><span>
</span><span id="line-1267"></span><span>          </span><span id="local-6989586621680963945"><span class="annot"><span class="annottext">lhs_fvs :: VarSet
</span><a href="#local-6989586621680963945"><span class="hs-identifier hs-var hs-var">lhs_fvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreExpr] -&gt; VarSet
</span><a href="GHC.Core.FVs.html#exprsFreeVars"><span class="hs-identifier hs-var">exprsFreeVars</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><a href="#local-6989586621680963956"><span class="hs-identifier hs-var">rule_args</span></a></span><span>     </span><span class="hs-comment">-- Includes template tyvars</span><span>
</span><span id="line-1268"></span><span>          </span><span id="local-6989586621680963946"><span class="annot"><span class="annottext">match_fn :: CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="#local-6989586621680963946"><span class="hs-identifier hs-var hs-var">match_fn</span></a></span></span><span> </span><span id="local-6989586621680963944"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963944"><span class="hs-identifier hs-var">rule_arg</span></a></span></span><span> </span><span id="local-6989586621680963943"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963943"><span class="hs-identifier hs-var">arg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
-&gt; RuleSubst -&gt; CoreExpr -&gt; CoreExpr -&gt; Maybe RuleSubst
</span><a href="GHC.Core.Rules.html#match"><span class="hs-identifier hs-var">match</span></a></span><span> </span><span class="annot"><span class="annottext">RuleMatchEnv
</span><a href="#local-6989586621680963942"><span class="hs-identifier hs-var">renv</span></a></span><span> </span><span class="annot"><span class="annottext">RuleSubst
</span><a href="GHC.Core.Rules.html#emptyRuleSubst"><span class="hs-identifier hs-var">emptyRuleSubst</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963944"><span class="hs-identifier hs-var">rule_arg</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963943"><span class="hs-identifier hs-var">arg</span></a></span><span>
</span><span id="line-1269"></span><span>                </span><span class="hs-keyword">where</span><span>
</span><span id="line-1270"></span><span>                  </span><span id="local-6989586621680963941"><span class="annot"><span class="annottext">in_scope :: InScopeSet
</span><a href="#local-6989586621680963941"><span class="hs-identifier hs-var hs-var">in_scope</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; InScopeSet
</span><a href="GHC.Types.Var.Env.html#mkInScopeSet"><span class="hs-identifier hs-var">mkInScopeSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680963945"><span class="hs-identifier hs-var">lhs_fvs</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; VarSet -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#unionVarSet"><span class="hs-operator hs-var">`unionVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; VarSet
</span><a href="GHC.Core.FVs.html#exprFreeVars"><span class="hs-identifier hs-var">exprFreeVars</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680963943"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1271"></span><span>                  </span><span id="local-6989586621680963942"><span class="annot"><span class="annottext">renv :: RuleMatchEnv
</span><a href="#local-6989586621680963942"><span class="hs-identifier hs-var hs-var">renv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RV :: RnEnv2 -&gt; VarSet -&gt; Subst -&gt; (Var -&gt; Unfolding) -&gt; RuleMatchEnv
</span><a href="GHC.Core.Rules.html#RV"><span class="hs-identifier hs-type">RV</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rv_lcl :: RnEnv2
</span><a href="GHC.Core.Rules.html#rv_lcl"><span class="hs-identifier hs-var">rv_lcl</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; RnEnv2
</span><a href="GHC.Types.Var.Env.html#mkRnEnv2"><span class="hs-identifier hs-var">mkRnEnv2</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680963941"><span class="hs-identifier hs-var">in_scope</span></a></span><span>
</span><span id="line-1272"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_tmpls :: VarSet
</span><a href="GHC.Core.Rules.html#rv_tmpls"><span class="hs-identifier hs-var">rv_tmpls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680963957"><span class="hs-identifier hs-var">rule_bndrs</span></a></span><span>
</span><span id="line-1273"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_fltR :: Subst
</span><a href="GHC.Core.Rules.html#rv_fltR"><span class="hs-identifier hs-var">rv_fltR</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Subst
</span><a href="GHC.Core.Subst.html#mkEmptySubst"><span class="hs-identifier hs-var">mkEmptySubst</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680963941"><span class="hs-identifier hs-var">in_scope</span></a></span><span>
</span><span id="line-1274"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rv_unf :: Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rv_unf"><span class="hs-identifier hs-var">rv_unf</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv -&gt; Var -&gt; Unfolding
</span><a href="GHC.Core.Rules.html#rc_id_unf"><span class="hs-identifier hs-var hs-var">rc_id_unf</span></a></span><span> </span><span class="annot"><span class="annottext">RuleCheckEnv
</span><a href="#local-6989586621680963988"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1275"></span></pre></body></html>